我知道我可以在PHP中实现这一点,但我真的需要在单个查询中使用它以便更轻松地进行分页。我有两个表如下:
S_MATTERS
id | name
---------------------
0 | Client 1
1 | Client 2
2 | Client 3
S_LINKS
mid | uid
---------------------
2 | 0007
0 | 0007
所以我想
select * from s_matters where id = (select mid from s_links where uid = 0007)
显然这不是正确的语法,我只需要从s_matters表中获取所有客户端名称,其中uid是另一个表上的0007(s_matters = mid上s_links上的id)。
答案 0 :(得分:6)
select m.*
from s_matters m
inner join s_links l
on m.id = l.mid
where l.uid = '0007'
答案 1 :(得分:0)
尝试将“=”更改为“in”
select * from s_matters where id in (select mid from s_links where uid = 0007)
答案 2 :(得分:0)
SELECT * FROM s_matters JOIN s_links ON ( s_matters.id = s_links.mid ) WHERE s_links.uid = '0007'
答案 3 :(得分:0)
您正在寻找内部联接
select * from s_matters
inner join s_links on s_links.mid = s_matters.id
where s_links.uid = '0007'