Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +----+--------+
- | id | name |
- +----+--------+
- | 2 | robin |
- | 3 | jyothi |
- | 1 | angel |
- +----+--------+
- +----+---------+--------+
- | id | hobbies | ref_id |
- +----+---------+--------+
- | 1 | walking | 1 |
- | 2 | chating | 1 |
- | 3 | reading | 2 |
- | 4 | walking | 2 |
- +----+---------+--------+
- +----+-----------------+
- | name | hobbies |
- +----+-----------------+
- | 1 | walking,chating |
- | 3 | reading,surfing |
- +----+-----------------+
- select name, group_concat(hobbies) as all_hobbies
- from test1,test2
- where test1.id = test2.ref_id
- and test1.id in (select ref_id
- from test2
- where hobbies = 'walking')
- group by name
- select name, group_concat(hobbies) as all_hobbies
- from test1,test2
- where test1.id = test2.ref_id and test1.name = 'robin'
- group by name
- having all_hobbies like '%walking%'
- having all_hobbies like '%walking%' or
- name like '%robin%'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement