Hi all,
I currently have two tables that look like this:
COMMENTS
+----+-------------------------+--------------+---------+---------------------+----------+
| ID | comment | profile_post | creator | created | approved |
+----+-------------------------+--------------+---------+---------------------+----------+
| 1 | This is a test comment | 3 | 1 | 2016-02-26 12:26:36 | 1 |
| 2 | 0 | 0 | 0 | 0000-00-00 00:00:00 | 1 |
| 3 | TEST TES TEST TEST ETST | 3 | 0 | 2016-02-26 12:34:34 | 1 |
| 4 | TEST TES TEST TEST ETST | 3 | 1 | 2016-02-26 12:34:34 | 1 |
+----+-------------------------+--------------+---------+---------------------+----------+
LIKES
+----+-------------------------+--------------+---------+---------------------+----------+
| ID | comment | profile_post | creator | created | approved |
+----+-------------------------+--------------+---------+---------------------+----------+
| 1 | This is a test comment | 3 | 1 | 2016-02-26 12:26:36 | 1 |
| 2 | 0 | 0 | 0 | 0000-00-00 00:00:00 | 1 |
| 3 | TEST TES TEST TEST ETST | 3 | 0 | 2016-02-26 12:34:34 | 1 |
| 4 | TEST TES TEST TEST ETST | 3 | 1 | 2016-02-26 12:34:34 | 1 |
+----+-------------------------+--------------+---------+---------------------+----------+
I use two queries to get the number of likes and comments in relation to any profile post:SELECT
IDFROM comments WHERE profile_post = {value}
and SElECT
IDFROM likes WHERE profile = {value}
I have been trying to combine these into one query. However, I get repeated values using:SELECT c.ID, l.ID FROM comments c, likes l WHERE c.profile_post = 3 and c.approved = 1 and l.status = 3;
This outputs:
+----+---------+
| ID | ID |
+----+---------+
| 3 | 4 |
| 1 | 4 |
| 4 | 4 |
| 3 | 5 |
| 1 | 5 |
| 4 | 5 |
| 3 | 6 |
| 1 | 6 |
| 4 | 6 |
| 3 | 7 |
| 1 | 7 |
| 4 | 7 |
+----+---------+
`
As you may have noticed, this outputs the CORRECT values, but repeats them 4 times... Any idea why?