PostgreSQL-INNER JOIN两个带有LIMIT的表 [英] PostgreSQL - INNER JOIN two tables with a LIMIT
本文介绍了PostgreSQL-INNER JOIN两个带有LIMIT的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看过这篇帖子,该帖子与我的问题几乎吻合,但我的特定问题是我需要对第三个表/查询设置限制,例如在 LIMIT 15
中。有没有简单的方法可以做到这一点?谢谢!
编辑
我的SQL SELECT语句如下所示:
选择t2.name AS用户名,t3.name AS艺术家名
FROM tbl1 t1
INNER JOIN tbl2 t2 ON t1.t1able_id = t2.id
INNER JOIN(选择*从tbl3 WHERE artist_id = 100极限15)t3
ON t2.id = t3.artist_id
W1哪里t1.kind ='澄清一下:这只是联接两个表的问题,但是第二个表具有两个状态。第一个状态为普通用户,第二个状态为艺术家(均使用相同的表,例如 users
)。解决方案尝试以下查询:
select *
from
tableA a
内部联接
tableB b
on a.common = b.common
内部联接
(select * from tableC order by some_column limit 15)b.common上的c
= c.common
I've seen this post which almost coincides with my question but my specific problem is that I need to put a limit to the third table/query, as in LIMIT 15
, for example. Is there an easy way to achieve this? Thanks!
EDIT
My SQL SELECT statement would look something like this:
SELECT t2.name AS user_name, t3.name AS artist_name
FROM tbl1 t1
INNER JOIN tbl2 t2 ON t1.t1able_id = t2.id
INNER JOIN (SELECT * FROM tbl3 WHERE artist_id = 100 limit 15) t3
ON t2.id = t3.artist_id
WHERE t1.kind = 'kind'
To clarify: It's just a matter of joining two tables but the second table has two states. First state as a "common user" and the next state as an "artist" (both using the same table, e.g. users
).
解决方案 Try this query:
select *
from
tableA a
inner join
tableB b
on a.common = b.common
inner join
(select * from tableC order by some_column limit 15) c
on b.common = c.common
这篇关于PostgreSQL-INNER JOIN两个带有LIMIT的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文