[英]The correct way to use NOT IN in a mysql query
I have a mysql query that throws an error which I'm guessing is because of my judicious use of the phrase "NOT IN": 我有一个mysql查询,抛出一个错误,我猜是因为我明智地使用短语“NOT IN”:
$sqlGetCountry = mysqli_query($link, "SELECT * FROM locations WHERE country='$country' AND CURTIME() > time AND '$state' NOT IN state ORDER BY time desc LIMIT 20");
$sqlNumCountry = mysqli_num_rows($sqlGetCountry);
I have a table with city, state, and country and I'm basically trying to find the queries where a given state ($state in this case, which could be Texas, Hawaii, etc.) is not in the results. 我有一个包含城市,州和国家的表格,我基本上试图查找给定状态(在这种情况下为$州,可能是德克萨斯州,夏威夷州等)的查询不在结果中。 I get the error:
我收到错误:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Anybody have a clue? 有人有线索吗?
You can't pass a table to in
, but you can pass a subquery: 你不能传递一个表
in
,但你可以通过一个子查询:
SELECT *
FROM locations
WHERE country='$country'
AND CURTIME() > time
AND '$state' NOT IN (select state from state)
ORDER BY
time desc
LIMIT 20
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.