tags:

views:

23

answers:

1

Hi-- I have a simple mySQL problem--

I have two tables, one is a user's table, and one is a photos table (each user can upload multiple photos).

I'd like to write a query to join these tables, so I can pull all photos associated with a user (up to a certain limit).

However, when I do something obvious like this:

SELECT *.a, *.b FROM user_table a
  JOIN photos_table b ON a.id = b.userid

it returns

a.id, a.name, a.email, a.address, b.id, b.userid, b.photo_title, b.location

but it only returns a single photo. Is there a way to return something like:

a.id, a.name, a.email, a.address, b.id, b.userid, b.photo_title, b.location, b.id2, b.photo_title2, b.location2 etc. . .

for a given LIMIT of photos?

Thanks for any ideas.

A: 

This is two separate types of data so it is best done with two separate queries:

SELECT * FROM user_table WHERE userid = @userid;
SELECT * FROM photos_table WHERE userid = @userid;

Combining it all into one mega-row is not the SQL way and is just asking for problems. You'll probably hit internal limits in the database at some point.

Mark Byers