請教C中sql查詢語句的問題,請教一個C 中sql查詢語句的問題

2022-09-30 17:00:10 字數 795 閱讀 2954

1樓:匿名使用者

可以這樣寫,只要在欄位列表那裡出現的欄位名不是兩個表內都存在,例如:table1(a,b,c),table2(b,c,d) 這時寫 select a,b,c from table1,table2 where table1.b=table2.

b就會出錯,應該寫成select table1.a,table1.b,table1.

c from table1,table2 where table1.b=table2.b

2樓:

只要你要查詢的欄位不同時存在於兩個表中就可以像你這樣不加別名來寫,但是為了便於閱讀和理解,也能幫助資料庫進行解析,最好給表加上別名。你上面的sql加上別名以後如下:

select b.friendid, a.nickname, a.faceid

from users a, friends b

where b.hostid =

and a.id = b.friendid

加上別名後是不是更方便寫,也更方便找到欄位來自於哪個表呢?

3樓:匿名使用者

select f.friendid,f.nickname,u.

faceid fom users as u left join friends f on u.id=f.friendid這樣寫

4樓:渁龍蠍

inner join on

5樓:匿名使用者

select後面要查詢的欄位要加上對應的表名

C解析sql語句,C 中 SQL 查詢語句

語法錯誤 bai你在from後面的是一串dusql語句,所以語zhi句後是要加別名的。試試 daoselect sum 總額 回 from select distinct 合同,總額 from table where 專案 aa and型別答 a as tab select sum 總額 from ...

sql語句,sql怎麼迴圈查詢,把list中的所有值當做查詢條件,查詢符合這個list的所有的資料

select f1 from table1的結果集做為查詢條件迴圈查詢。如 set a select f1 from table1foreach a sql 語句是對資料庫進行操作的一種語言。結構化查詢語言 structured query language 簡稱sql,結構化查詢語言是一種資料庫查...

sql語句問題,請高手幫忙

select 學生.學號,姓名 from 學生,選課 選課1 where 學生.學號 選課1.學號 and not exists select from 選課 選課2 where 選課2.學號 s001 and not exists select from 選課 選課3 where 選課2.課程號 ...