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
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%'

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.