"SELECT 1 FROM identity_approve WHERE identity_num=' " . trim($_POST['IDnumber']) . " ' AND user_id !=".trim($_POST['uid']); 到底會有什么輸出?
select 1 from table;
select xxx(表集合中的任意一行) from table;
select * from table
從作用上來說是沒有差別的,都是查看是否有記錄,一般是作條件查詢用的。
select 1 from 中的1是一常量(可以為任意數值),查到的所有行的值都是它,但從效率上來說,1>xxx>*,因為不用查字典表。
1:select 1 from table 增加臨時列,每行的列值是寫在select后的數,這條sql語句中是1
2:select count(1) from table 管count(a)的a值如何變化,得出的值總是table表的行數
3:select sum(1) from table 計算臨時列的和
一般用來當做判斷子查詢是否成功(即是否有滿足條件的時候使用)
比如:select * from ta where exists (select 1 from ta.id = tb.id)
這個判斷就是(select 1 from ta.id = tb.id)這個查詢如果有返回值的話表示當前查詢滿足條件,一般來說就簡單話的用select 1 當然也可以用select * ,或者select 任何東東,因為這里僅僅是表明子查詢有結果就行了,至於什么結果無所謂。