I need to group MySQL result, from property table and category table but I can't understand how can I do it ?
I have 6 category column in property table
SELECT p.*, c.*, p.id id
FROM property p
JOIN clients c
ON p.user_id = c.id
LEFT JOIN category ct1
ON ct1.id = p.cat1
LEFT JOIN category ct2
ON ct2.id = p.cat2
LEFT JOIN category ct3
ON ct3.id = p.cat3
LEFT JOIN category ct4
ON ct4.id = p.cat4
LEFT JOIN category ct5
ON ct5.id = p.cat5
LEFT JOIN category ct6
ON ct6.id = p.cat6
WHERE public = '1'
AND (p.cat1 = '$cat'
OR p.cat2 = '$cat'
OR p.cat3 = '$cat'
OR p.cat4 = '$cat'
OR p.cat5 = '$cat'
OR p.cat6 = '$cat')
GROUP BY ct1.id, ct2.id, ct3.id, ct4.id, ct5.id, ct6.id
ORDER BY p.id DESC
I need 5 result where cat ID is "41"
Thank you
EDITED:
I think this method is not for me, because I have multi category column
can anyone help me?
$SQL = "SELECT p.*, c.*, p.id id
FROM property p
JOIN clients c
ON p.user_id = c.id
WHERE public = '1'
AND p.cat1 IN ($cat)
OR p.cat2 IN ($cat)
OR p.cat3 IN ($cat)
OR p.cat4 IN ($cat)
OR p.cat5 IN ($cat)
OR p.cat6 IN ($cat)
ORDER BY p.id DESC";
I get only one result, but I need three result, two times ID 99 and one times 93
Thank you