我是SQL的新手,为了学习,我试图在SQL中进行一些查询。所以我做了这两个表:
account(id, email, password)
address(id, city, street, c_id(foreign key for account))
现在我想选择一个城市的所有电子邮件。贝娄我试过的。
SELECT email
FROM account
WHERE id=(SELECT c_id
FROM address
WHERE city='new york');
此查询无效!
答案 0 :(得分:0)
你可以用这个
SELECT email
FROM account
WHERE id in (SELECT c_id
FROM address
WHERE city='new york');
或
SELECT email
FROM account
JOIN address ON account.id = address.c_id
WHERE address.city='new york'