开发者

How to select common rows between 6 databases and order the result?

开发者 https://www.devze.com 2023-03-30 19:17 出处:网络
I have very large databases, 3 databases for users each one containing only one table called index and very large databases

I have very large databases,

  • 3 databases for users each one containing only one table called index and very large databases
  • 3 databases for status update each one containing only one table called index

I wanna get the mutual rows between the 6 databases how to select and order them???

    SELECT * FROM db1, db2, db3, db4, db5, db6 WHERE db1.index.user_id, db2.index.user_id,
 db3.index.user_id = db4.index.user_id, db5.index.user_id, db6.index.user_id ORDER BY
 db1.index.name, d开发者_Go百科b2.index.name, db3.index.name

Is there a way to make this code ???


Not tested but it might work.

select * from (
SELECT d1.user_id,d1.username as uname from db1.`index` as d1
union all
SELECT d2.user_id,d2.username from db2.`index` as d2
...
) as t
group by user_id
having count(user_id) = 6
order by uname
0

精彩评论

暂无评论...
验证码 换一张
取 消