我有一个表格,用于存储location
user
正在观看的每个usercity
。该表名为SELECT
,如下图所示。
我需要user_id='1'
所有行WHERE location_id
,然后从location
表中检索每个 SELECT b.* FROM usercity a JOIN location b ON a.location_id=b.id WHERE user_id='1'
的记录,如下图所示:
我不确定从哪里开始,但这是我的蹩脚尝试:
{{1}}
编辑我的查询使用一条记录。不确定它是否适用于多行。
答案 0 :(得分:1)
try below-
select a.*, b.*
from usercity a JOIN location b ON a.location_id=b.id
WHERE user_id=:uid
答案 1 :(得分:1)
If its one-to-one relation then you can use inner join
select
uc.*,
l.* from usercity uc
join location l on l.location_id = uc.location_id
where l.user_id=:uid
答案 2 :(得分:0)
well, i kept playing with it and got what i want:
SELECT b.* FROM usercity a JOIN location b ON a.location_id=b.id WHERE user_id='1'
I guess SQL is one of those things you learn through practice.