1、最簡單的單條件查詢,where指定查詢條件。
select messagetype,messagename from t_sr_message where messagename='manage'
下面列舉幾個查詢條件,不是全部:
2、分組查詢
select superno,typename from t_sr_messagetype group by SUPERNO,typename having typename<'200'
//根據superno,typename分組返回superno和typename2個列的記錄,並且要滿足typename<200這個條件。
//根據superno,typename分組返回superno和typename2個列的記錄,並且要滿足typename<200這個條件。
3、排序查詢
select * from t_sr_messagetype order by DESC
4、轉換查詢
select userid 用戶編號, username 用戶名稱, userpwd 用戶密碼 from userinfo
查詢結果如下:
用戶編號 | 用戶名稱 | 用戶密碼 |
1 | sword | 123456 |
2 | niuniu | 654321 |
5、計算查詢
select logincount+exitcount from userinfo
6、等值多表查詢
等值多表查詢將按照等值的條件查詢多個數據表中關聯的數據,要求關聯的多個數據表的某些字段具有相同的數據類型、寬度和取值範圍
select A.name,B.typename from A,B where A.Id = B.Id
非等值多表查詢與此類似。
7、一個帶‘in’的嵌套查詢
select news.newtitle from news where news.USERID in (select userid from userinfo where
username <> 'sword')
username <> 'sword')
查詢結果要滿足條件:先看後面的,查詢出userinfo表中username不等於‘sword’的所有userid,然後再得出news表中userid在前面得到的userid裏的所有news.newtitle記錄。