ultra_magnotron Posted June 1, 2012 Share Posted June 1, 2012 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? Quote Link to comment Share on other sites More sharing options...
gristoi Posted June 1, 2012 Share Posted June 1, 2012 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 Quote Link to comment Share on other sites More sharing options...
ultra_magnotron Posted June 1, 2012 Author Share Posted June 1, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.