Guest User

Untitled

a guest
Feb 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. I want to JOIN only the last item
  2.  
  3. table_1
  4. ------------
  5. id | Name |
  6. ============
  7. 1 Bob |
  8. ============
  9.  
  10. table_2
  11. ---------------------------
  12. id | table_1_id | height |
  13. ===========================
  14. 1 1 191 |
  15. 2 1 193 |
  16. ===========================
  17.  
  18. SELECT * FROM table_1
  19. INNER JOIN table_2 ON table_1.id = table_2.table_1_id
  20.  
  21. Result:
  22. =================================
  23. 1 Bob 1 1 191 |
  24. 1 Bob 2 1 193 |
  25. =================================
  26.  
  27. What I want:
  28. =================================
  29. 1 Bob 2 1 193 |
  30. =================================
  31.  
  32. What I came up with:
  33. SELECT * FROM table_1
  34. INNER JOIN (SELECT * from table_2 ORDER BY id DESC LIMIT 1) as table_2 ON table_1.id = table_2.table_1_id
Add Comment
Please, Sign In to add comment