#1054 - 未知专栏'布里斯班'在' where子句'

时间:2016-03-15 08:27:54

标签: mysql sql

编写一个使用子查询的SQL语句来检索有关来自布里斯班的客人的所有信息?

SELECT * FROM guest
WHERE guestCity = Brisbane IN (SELECT guestCity FROM guest
                               WHERE guestCity = Brisbane)

但它一直说:

  

1054 - 未知专栏'布里斯班'在' where子句'

我不知道自己做错了什么。有人可以解决一些问题吗?

guestNo, guestName, guestAddress, guestCity, guestState, guestPostcode
1, Bill Watson, 56 Gee Street, Brisbane, QLD, 4000
2, Sharon Stone, 64 New Drive, Sydney, NSW, 2000
3, Mark Harris, 100 Regents Park Road, Brisbane, QLD ,4000
4, Silvia Smith, 312 West Road, Melbourne, VIC, 3000

2 个答案:

答案 0 :(得分:1)

可以试试这个查询吗?它将返回正在拥有的客人名单 guestCity为' Brisbane'

SELECT * FROM guest 
WHERE guestCity = 'Brisbane'

答案 1 :(得分:0)

您不需要子查询来返回您需要的内容。

您还需要用单引号

包装字符串
SELECT g.* 
FROM guest g
WHERE g.guestCity = 'Brisbane'

子查询

SELECT g.* 
FROM guest g
WHERE g.guestCity IN (SELECT sg.guestCity 
                      FROM guest sg
                      WHERE sg.guestCity = 'Brisbane')