news表:
tag表:
为什么用下面这条SQL语句
select * from tag where tid in (select tids from news where nid=1);
查询结果是:
1 PHP
我想要的查询结果是:
1 PHP
2 Mysql
3 Apache
SELECT .. IN ..
没有办法做到这一点,可以试试 FIND_IN_SET
: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_...
要实现你想要的结果可以这样写:
select find_in_set(tid, (select tids from news where nid=1)) as id, name from tag;
没这么复杂啦
select * from tag where tid instr (select tids from news where nid=1);就行了