1.like 用于在where子句中搜索列中的指定模式 示例: select * from websites where name like '%oo%'; 注:(%分號表示任意數據,_表示任意一個數據,動手練兩邊就能熟悉) 'G%' 搜索以G開頭的數據 '%G' 搜索以G結尾的數據 '%g%' 搜索包含g的數據 'G' 搜索以G開頭的兩位數據 'G' 搜索以G結尾的兩位數據 'G' 搜索包含G的三位數據
1.1 通配符還有一種(%、_和[charlist]) 示例:[charlist]使用 select * from websites where name REGEXP '^[A-H]';
2.between 用于選取介于兩個值之間的數據范圍內的值 示例: select * from websites where alexa between 1 and 20; 示例:添加not使用 select * from websites where alexa not between 1 and 20; 示例:結合IN使用 select * from websites where ( alexa BETWEEN 1 and 20) and country in ('USA','CN'); 示例:文本 select * from websites where name between 'A' and 'H'; 不包含H
3.top 用于規定返回記錄的數據,實用 示例:SQL server (SELECT TOP number|percent column_name(s) FROM table_name;) select top 50 percent * from websites; 示例:Oracle(SELECT column_name(s) FROM table_name WHERE ROWNUM <= number;) select * from websites where ROWNUM <5; 示例:MYSQL (SELECT column_name(s) FROM table_name LIMIT number;) select * from websites limit 3;
4. join 子句用于把來自兩個表或者多個表的行結合起來,基于這些表之間的共同字段 join類型有一下幾種: INNER JOIN:如果表中有至少一個匹配,則返回行 LEFT JOIN:即使右表中沒有匹配,也從左表返回所有的行 RIGHT JOIN:即使左表中沒有匹配,也從右表返回所有的行 FULL JOIN:只要其中一個表中存在匹配,則返回行(MYSQL不支持)