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