Jump to content

Join 4 tables


rashmi_k28

Recommended Posts

Hi,

 

Here is the queries below.

How to join all the tables into one single query

 

select cid from c_table limit 1;

select * from g_table where cid='4';

select * from a_table where gid='43';

select count(*) from k_table where aid='48';

 

I have to remove limit from c_table,

I have to fetch all the cid's from c_table where count(*) from k_table is greater than 1

Link to comment
https://forums.phpfreaks.com/topic/157070-join-4-tables/
Share on other sites

Thanks for the query. This works.

How to get the count of a.cid where KidCount >=1

 

SELECT a.cid, count(kid) as KidCount
FROM c_table a
INNER JOIN g_table b ON a.cid = b.cid
INNER JOIN a_table c ON b.gid = c.gid
INNER JOIN k_table d ON c.aid = d.aid
GROUP BY a.cid
HAVING KidCount > 1

Link to comment
https://forums.phpfreaks.com/topic/157070-join-4-tables/#findComment-832211
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.