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.

$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'
");

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.