0

i have two tables in database

  1. users{id, username, email, etc...}

  2. photos{photo_description, uploaded_on, uploaded_by,etc...}

each time the page loads, i display all the images and details except username

now i need to get the usernames of the uploaders of the photos i have in photos db, i have only the ids of the users...

i tried to join the tables, but i am worried that there are more than 10k users, but hardly hundreds of them uploaded pics.

help with sql query to get the result quickly

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309

1 Answers1

0

Join is the right way

Select p.*, u.username from photos p join users u on (u.id = p.uploaded_by)

Then you can get all photo-cols and the corresponding username to this photo.

(Sorry for format, writing from mobile phone)

Atur
  • 1,712
  • 6
  • 32
  • 42
bish
  • 3,381
  • 9
  • 48
  • 69
  • well thanks... :) i figured out this one for my problem using inner join.... SELECT * FROM photos inner join users on users.id=photos.updated_by thank you all :) – Bhavan Kuchibhotla Jun 17 '13 at 16:05