我正在尝试选择一个用户(例如用户2),让他显示所有用户的内容,哪个字段有字符串" happy"包括在内。
表有两个字段,id和content。所以表格就是这样。
id content
1 happy days
2 sad days
3 not very happy
etc...
我希望结果有点
2 not very happy happy days etc.
这可能吗?我尝试过以下方法:
select *
from table
where id = 2
or join table.content on table.content LIKE 'happy%'
答案 0 :(得分:0)
我想你只想要group_concat()
:
select group_concat(t.content separator ' ')
from table t
where t.id = or t.content like 'happy%'
如果值可以在不同的行上,那么您只需要where
子句。
答案 1 :(得分:0)
Gordon Linoff的回答是正确的,只需添加明确的内容:
select id,group_concat( distinct content separator ' ')
from table
where id = 2
or table.content LIKE 'happy%'