使用where子句 數(shù)據(jù)庫表一般包含大量的數(shù)據(jù),很少需要檢索表中的所有行。通常會(huì)根據(jù)特定操作或報(bào)告的需要提取表數(shù)據(jù)的子集。 例如:查找年齡等于22歲的行 MariaDB [test]> select age -> from user -> where age=22; +------+ | age | +------+ | 22 | +------+ 1 row in set (0.00 sec)
提示:在同時(shí)使用order by 和 where子句時(shí),應(yīng)該讓order by位于where之后。
where子句操作符 等于、不等于、小于、小于等于、大于、大于等于、在指定的兩個(gè)值之間使用between 2.1 檢查單個(gè)值 MariaDB [test]> select id,age,province -> from user -> where province = '北京'; +----+------+----------+ | id | age | province | +----+------+----------+ | 1 | 22 | 北京 | | 4 | 14 | 北京 | | 7 | 45 | 北京 | | 11 | 29 | 北京 | | 13 | 24 | 北京 | +----+------+----------+ 5 rows in set (0.01 sec)