1

I have two tables:

id  category    status
1   test        1
2   test1       1
3   test2       1

This is the group_master table.

groupid     groupname   groupmaster 
1           yy          1
2           xx          1
3           yyyy                1
4           xrx         1
5           yy          2
6           xx          2
7           yyyy                2
8           xfgdrx              3

This is the membergroup table.

The group_master.id is same as in membergroup.groupmaster.That menas i want to get each row from first table and also want to get the count from second table

That means:

id  category    status  Count
1   test        1       4
2   test1       1       3
3   test2       1       1

This is the result i want to get.

How can i do this in Cakephp with pagination ?

1 Answer 1

2

try this:

You need to JOIN both tables and do a GROUP BY

SELECT g.id,g.category,g.status,count(*) as Count
FROM   group_master g
JOIN   membergroup m
ON     g.id=m.groupmaster
GROUP BY g.id,g.category,g.status


SQL Fiddle Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.