Jump to content

Help Querying Two Tables at Once


ardesigns

Recommended Posts

Hi. I have two tables, photos2011 and photos2012. The columns are:

 

Photos2011

-id

-first

-last

-filename2011

 

Photos2012

-id

-first

-last

-filename2012

 

Both tables have several rows that overlap in columns first and last (but the ids may not be the same), and both have some rows that do not overlap with the other table. Also, the filename2011/filename2012 values are completely different for both tables, even when they correspond to the same first and last values.

 

For example, 2 rows in photos2011 might be:

 

id/first/last/filename2011

0/Bob/Smith/9hfsdf.png

3/John/Doe/jdsf234.png

 

and in photos2012:

 

id/first/last/filename2012

3/Bob/Smith/sdjf.jpg

4/Sarah/Jones/sdjf.jpg

 

 

What I want to do, ultimately, is allow the user to search by last name (last), and to output a table that shows first name (first), last name, photos2011 (if one exists), and photos2012 (if one exists). I don't want any duplicate rows to appear.

 

How can I use MySQL and PHP to do this? I have a good amount of experience with PHP and with MySQL, but only with simple MySQL tasks (insert, update, delete, and simple SELECT queries), so I haven't been able to figure out how to do this.

 

Sorry if this is confusing, please let me know if I need to clarify something.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/244710-help-querying-two-tables-at-once/
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.