询问
SELECT * FROM stack WHERE username = "admin" AND password = "admin";
结果
+------+----------+----------+ | id | username | password | +------+----------+----------+ | 1 | admin | admin | +------+----------+----------+ 1 row in set (0.00 sec)
该WHERE子句可以包含任何有效的SELECT语句以编写更复杂的查询。这是一个“嵌套”查询
询问
嵌套查询通常用于从查询中返回单个原子值以进行比较。
SELECT title FROM books WHERE author_id = (SELECT id FROM authors WHERE last_name = 'Bar' AND first_name = 'Foo');
选择所有没有电子邮件地址的用户名
SELECT * FROM stack WHERE username IN (SELECT username FROM signups WHERE email IS NULL);
免责声明:比较整个结果集时,请考虑使用联接来提高性能。