Jump to content

Using a Query To Intersect another Table


mofolo

Recommended Posts

Hey Guys,

 

I need to intersect a table using the values from a query..

 

For Example:

 

$myData = mysql_query("SELECT theID FROM myData WHERE myID = '$userID'");

 

Now I need to use the Multiple Results returned into the Query $myData to look for data in another table.

 

For Example:

mysql_query("SELECT * FROM otherTable WHERE personID = '$myData'")

 

(that Query Will not work...)

 

So what I am trying to do is return the list of 'theID' from the table 'myData'. Then with the list of IDs, get all the related rows from 'otherTable'.

 

Whats the most effective and efficient way of getting it using mySQL?

 

Thanks.

Link to comment
Share on other sites

I've look at some Tutorials about Join, but they're confusing.

 

I tried this with no luck.

 

"SELECT theID FROM myData JOIN otherTable ON myData.id = otherTable.id WHERE personID = '$id'"

 

But it only Returns and Joins the first row.

Link to comment
Share on other sites

$myData = mysql_query("SELECT theID FROM myData WHERE myID = '$userID'");

mysql_query("SELECT * FROM otherTable WHERE personID = '$myData'")

 

So what I am trying to do is return the list of 'theID' from the table 'myData'. Then with the list of IDs, get all the related rows from 'otherTable'.

 

You're wanting to grab your first result and join your other table based on the id equalling the personID. I think I got what you want right here, not sure if the table-data matches to what you're doing but hopefully  ;D

 

$query = mysql_query("
SELECT *
FROM myData
INNER JOIN otherTable ON myData.myID = personID.otherTable
WHERE myID.myData = '$userID'
");

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.