Jump to content

Query two tables


ultra_magnotron

Recommended Posts

I need to query two separate tables in a database, but not just display data. The data needs to correspond to one another... if that makes sense.

 

Let's say one table has the name of a person. The other table has all the data for this person, so I need to query the name from one and then display the info on that person from another. I have it set up so that a list of names now displays on my site, so all of the info for these names needs to be displayed in that same list.

 

Am I making sense? Is this something that can be done in PHP? If so, how can I even get started on this?

Link to comment
https://forums.phpfreaks.com/topic/263464-query-two-tables/
Share on other sites

heres an example:

 

SELECT details.* FROM Person INNER JOIN details USING(user_id) WHERE Person.user_id = 123

In plain english you are saying select everything from the details table where the user_id stored in the details table matches the one in the person table ADN where the persons user_id equals 123

Link to comment
https://forums.phpfreaks.com/topic/263464-query-two-tables/#findComment-1350260
Share on other sites

heres an example:

 

SELECT details.* FROM Person INNER JOIN details USING(user_id) WHERE Person.user_id = 123

In plain english you are saying select everything from the details table where the user_id stored in the details table matches the one in the person table ADN where the persons user_id equals 123

 

Thank you for replying.

 

If I understand correctly, "details.*" is going to the name of the table where all of the details are stored and then using the user_id is how the details will be selected to correspond to the correct person in this list?

 

I just want to be clear because there will be a many different people and details to be listed. I don't want to get information mixed up in the query results.

Link to comment
https://forums.phpfreaks.com/topic/263464-query-two-tables/#findComment-1350331
Share on other sites

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.