繁体   English   中英

内连接限制第二个表中的行

[英]Inner join limit the rows from second table

有 2 个表queriestransactions ,1 个事务可以有多个查询。 我想获取 10 个交易的查询列表。 我试过这个查询,但这限制了总行数。

SELECT t.tid
     , q.id
     , q.timestamp
     , q.domain
     , q.health
     , q.alexa_rank
     , q.destination
     , t.age
     , t.sb_isValid
     , t.userResponse
     , t.suggestion 
  from queries q 
  join transactions t 
    on q.id like concat(t.tid, '%') 
 where t.uid = '115800979895438175088' 
 order 
    by t.time DESC
     , tid 
 limit 10

此查询返回 10 行,包括查询和事务,但我想要 10 个事务及其查询。

如果有 10 个事务并且每个事务有 3 个查询,那么它应该返回 30+10 = 40 行,但它只返回 10 行。

在子查询中选择十个事务:

select *
from
(
  select *
  from transactions
  order by time desc
  limit 10
) t
join queries q on q.id like concat(t.tid, '%')
order by t.time desc, t.tid, q.timestamp desc;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM