This will get all results from table 1 where they appear in table 2, and get the highest ID of that result, and display the data!
1 2 3 4 5 6 7 8 9 10 |
SELECT * FROM table1 INNER JOIN ( SELECT MAX(table1.id) AS id FROM table1 INNER JOIN table2 ON table2.client = table1.client AND table2.campaign=table1.campaign AND table2.enabled != 'disabled' GROUP BY table1.client, table1.campaign ) AS m ON m.id = table1.id |
Another version using WHERE and AND
1 2 3 4 5 6 7 8 9 10 11 12 13 |
SELECT * FROM mydata INNER JOIN ( SELECT MAX(mydata.id) AS id FROM mydata INNER JOIN targets ON targets.client = mydata.client AND targets.campaign=mydata.campaign WHERE mydata.date='$thisday' AND mydata.client ='$boardname' AND targets.enabled != 'disabled' GROUP BY mydata.client, mydata.campaign ) AS m ON m.id = mydata.id order by mydata.campaign ASC |