[英]nested sql statement using and
how to make this work in mysql? 如何使它在mysql中工作?
select ID,COMPANY_NAME,contact1, SUBURB, CATEGORY, PHONE from Victoria where (city in ( select suburb from allsuburbs)) and CATEGORY='Banks' 选择来自维多利亚州的ID,COMPANY_NAME,contact1,SUBURB,CATEGORY,PHONE(城市(从所有郊区中选择郊区)),CATEGORY =“银行”
this below statement is working: select ID,COMPANY_NAME,contact1, SUBURB, CATEGORY, PHONE from Victoria where city in ( select suburb from allsuburbs) 下面的语句有效:从城市所在的维多利亚州选择ID,COMPANY_NAME,contact1,SUBURB,CATEGORY,PHONE(从所有郊区中选择郊区)
if I add "and" , it gives me an empty resultset, thanks 如果我加上“和”,它给我一个空的结果集,谢谢
Learn how joins work. 了解联接的工作方式。
select
v.ID,v.COMPANY_NAME,v.contact1,v.SUBURB,v.CATEGORY,v.PHONE
from
Victoria v
inner join allsuburbs s on s.suburb = v.city
where
v.CATEGORY='Banks'
Apart from that, your query does not make a whole lot of sense. 除此之外,您的查询没有任何意义。
Victoria
, but it contains a field named city
?! Victoria
,但其中包含一个名为city
?!的字段。 Do your other cities have their own table too? allsuburbs
, but your criterion is that Victoria.city
equals allsuburbs.suburb
, even though a field named Victoria.suburb
exists?! allsuburbs
的表,但您的条件是即使存在一个名为Victoria.suburb
的字段, Victoria.city
等于allsuburbs.suburb
吗? What's Victoria.suburb
for, then? Victoria.suburb
是什么? allsuburbs
. allsuburbs
。 Do you have another table that contains suburbs or is this your only one? contact1
. contact1
。 Do you have contact2
... contact10
as well? contact2
... contact10
? Bad database design. Oh, and the usual format for SQL is: SQL keywords in caps, the field names etc. in mixed case/lower case. 哦,SQL的常用格式是:大写的SQL关键字,大小写混合的字段名等。 Much easier to read.
更容易阅读。
I think you might have misplaced a parentheses? 我认为您可能放错了括号?
.. PHONE from Victoria where
(city in ( select suburb from allsuburbs)) and CATEGORY='Banks'
I'm guessing should be: 我猜应该是:
.. PHONE from Victoria where
city in ( select suburb from allsuburbs) and CATEGORY='Banks'
Not sure if that makes more sense, but the first case is not an ok SQL-statement I believe. 不知道这是否更有意义,但是我认为第一种情况不是好的SQL语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.