Jump to content

Help needed to query two tables at once


kingnutter

Recommended Posts

Hi everyone,

 

I have given this a good Googling but not found the answer.

 

I am trying to query two tables to produce one result, hopefully in one seamless query. Below is a hybrid Plain English / PHP version of exactly what I am trying to achieve.

 

{
$data = mysql_query("SELECT moj_id, track_artist, track_title FROM tracks WHERE upper(track_artist) LIKE '%$find%' OR upper(track_title) LIKE '%$find%' THEN SELECT moj_title FROM mojocd WHERE moj_id IS THE SAME AS THE ONE IN THE FIRST PART OF THIS QUERY");
}

 

Any pointers?

Link to comment
https://forums.phpfreaks.com/topic/168845-help-needed-to-query-two-tables-at-once/
Share on other sites

Learn how to use JOINS to really utilize a database

 

SELECT t.moj_id, t.track_artist, t.track_title, m.moj_title

FROM tracks t
JOIN mojocd m ON t.moj_id = m.moj_id

WHERE upper(t.track_artist) LIKE '%$find%'
   OR upper(t.track_title) LIKE '%$find%'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.