By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE blog(id integer, blog_title varchar(20), tags varchar(20));
INSERT INTO blog (id,blog_title,tags) VALUES(1,'Hi','台北,高雄,屏東');
INSERT INTO blog (id,blog_title,tags) VALUES(2,'你好','台北,高雄');
INSERT INTO blog (id,blog_title,tags) VALUES(3,'早安','屏東,彰化');
SELECT * FROM blog
id | blog_title | tags |
---|---|---|
1 | Hi | 台北,高雄,屏東 |
2 | 你好 | 台北,高雄 |
3 | 早安 | 屏東,彰化 |
SELECT id,blog_title FROM blog
WHERE tags REGEXP (
SELECT replace(tags,',','|') FROM blog
where 1=1
and id=1
)
and id <> 1
id | blog_title |
---|---|
2 | 你好 |
3 | 早安 |
SELECT id,blog_title FROM blog
WHERE tags REGEXP (
SELECT replace(tags,',','|') FROM blog
where 1=1
and id=2
)
and id <> 2
id | blog_title |
---|---|
1 | Hi |
SELECT id,blog_title FROM blog
WHERE tags REGEXP (
SELECT replace(tags,',','|') FROM blog
where 1=1
and id=3
)
and id <> 3
id | blog_title |
---|---|
1 | Hi |