MySQL complex join


SUBMITTED BY: Guest

DATE: Nov. 19, 2013, 3:20 a.m.

FORMAT: Text only

SIZE: 835 Bytes

HITS: 702

  1. MySQL complex join - Can't select multiple columns in second table
  2. Computers:
  3. ----------
  4. id, cond, type
  5. Images:
  6. -------
  7. id, foreignid, name, width, height, def
  8. SELECT
  9. id, cond, type,
  10. (SELECT name, width, height FROM images WHERE foreignid = computers.id ORDER BY def DESC LIMIT 1) AS image
  11. FROM computers
  12. Operand should contain 1 column(s)
  13. select c.id, c.cond, c.type, i.name, i.width, i.height from computers c
  14. left join images i on i.foreignid=c.id
  15. order by i.def desc limit 1
  16. computers left join images
  17. computers right join images
  18. computers inner join images
  19. computer outer join images
  20. SELECT comp.id, comp.cond, comp.type, img.name, img.height, img.width FROM computers comp left join image img on img.foreignid = comp.id

comments powered by Disqus