Below is a gross over simplification of 2 very large tables I'm working worth.
campaign
table
| id | uid | name | contact | pin | icon | | 1 | 7 | bob | ted | y6w | yuy | | 2 | 7 | ned | joe | y6e | ygy | | 3 | 6 | sam | jon | y6t | ouy |
records
table
| id | uid | cid | fname | lname | address | city | phone | | 1 | 7 | 1 | lars | jack | 13 main | lkjh | 55555 | | 2 | 7 | 1 | rars | jock | 10 maun | oyjh | 55595 | | 2 | 7 | 1 | ssrs | frck | 10 eaun | oyrh | 88595 |
The page loops thru the records table and prints the results to an HTML table. The existing code, for some reason, does a separate query for each record "select name from campaign where id = $res['cid']"
I'd like to get rid of the second query and do a some kind of join but what is the most effective way to do it?
I need to
SELECT * FROM records
and also
SELECT name FROM campaigns WHERE campaigns.id = records.cid
in a single query.
How can I do this efficiently?