开发者

mysql select data from multiple rows

开发者 https://www.devze.com 2023-01-17 02:50 出处:网络
I have a table id, name, keyword 1bobguy 2bobdeveloper 3marygirl 4joeguy Q1 : What would be the sql to get back the row (bob) containing both keywords \'guy\' AND \'developer\'?

I have a table

id, name, keyword
1   bob    guy
2   bob    developer
3   mary   girl
4   joe    guy

Q1 : What would be the sql to get back the row (bob) containing both keywords 'guy' AND 'developer'?

Intuitively, I tho开发者_如何学运维ught it'd be SELECT * FROM TABLE WHERE keyword = 'guy' AND keyword = 'developer'

Q2: But I suppose the first conditional AND removes the 2nd row (bob, developer) which causes the sql to return no result? Am I correct about this speculation?


SELECT * FROM TABLE WHERE keyword = 'guy' AND name in (SELECT name FROM TABLE WHERE keyword = 'developer')
0

精彩评论

暂无评论...
验证码 换一张
取 消