Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. +----+--------+
  2. | id | name |
  3. +----+--------+
  4. | 2 | robin |
  5. | 3 | jyothi |
  6. | 1 | angel |
  7. +----+--------+
  8.  
  9. +----+---------+--------+
  10. | id | hobbies | ref_id |
  11. +----+---------+--------+
  12. | 1 | walking | 1 |
  13. | 2 | chating | 1 |
  14. | 3 | reading | 2 |
  15. | 4 | walking | 2 |
  16. +----+---------+--------+
  17.  
  18. +----+-----------------+
  19. | name | hobbies |
  20. +----+-----------------+
  21. | 1 | walking,chating |
  22. | 3 | reading,surfing |
  23. +----+-----------------+
  24.  
  25. select name, group_concat(hobbies) as all_hobbies
  26. from test1,test2
  27. where test1.id = test2.ref_id
  28. and test1.id in (select ref_id
  29. from test2
  30. where hobbies = 'walking')
  31. group by name
  32.  
  33. select name, group_concat(hobbies) as all_hobbies
  34. from test1,test2
  35. where test1.id = test2.ref_id and test1.name = 'robin'
  36. group by name
  37. having all_hobbies like '%walking%'
  38.  
  39. having all_hobbies like '%walking%' or
  40. name like '%robin%'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement