php - Selecting A Joined Row -


If I have these two lines:

  user table UserId | Username Etc ... 5 | John | Avatar table id UserId | Image name | Image Type 1 | 5 | Example.png | | Origin 2 | 5 | Example_thumb.png | Thumbnail for  thumbnail   

and I have:

 choose  to add users to Avatar on Avatar.UserId = Avatar.UserId where users.UserId = 5 '  

I have additional to add:

  and Avatars.ImageType =' thumbnail '  

or is There's one to select all and one I want with php (like an array: $ var ['something']) ??

Is it possible to differentiate them with mysql by using something like "AS" section ?? ImageType

Multiple rows per record will be found

Edit:. For example select

  u.UserId, u.Username, a.ImageName, a.ImageType users join U interiors on Avatar one u.UserId = a. UserId Where u.UserId = 5 UserId User Name ImageName ImageType ---------------------- ---------------- -------------- 5 John example.png Basic 5 John example_thumb.png thumbnail   

Edit # 2: If you want both images in a line, then use this query

  SELECT u.UserId, u.Username, orig.ImageName as the original image, thumbImage form thumbImage as Image ImageName U inside Join the embodiment basic at u.UserId = orig.UserId and orig.ImageType = 'original' u.UserId = thumb.UserId and thumb.ImageType = 'thumbnail' Join Avatar Thumbs Where u.UserId = 5   

Note that this will only return the rows where both types are present in the avatar for the user. If you want to get results despite the existence of avatar images, then use the left join.

Comments