Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. Table1:
  2. id (uniqueidentifier, primarykey)
  3. title (varchar(50))
  4.  
  5. Table2:
  6. id (uniqueidentifier, primarykey)
  7. table1id (uniqueidentifier, foreignkey to table1)
  8. category (varchar(50))
  9.  
  10. select t1.*, t2.category as cat from table1 as t1
  11. left join table2 as t2 on t1.id = t2.table1id
  12.  
  13. Table2 row 1:
  14. id = 1
  15. table1id = 1
  16. category = "abc"
  17.  
  18. Table2 row 2:
  19. id = 2
  20. table1id = 1
  21. category = "def"
  22.  
  23. select t1.id, t1.title, group_concat(t2.category) as cat from table1 as t1
  24. left join table2 as t2 on t1.id = t2.table1id
  25. group by t1.id, t1.title
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement