Is it possible?
tag_table :
tag postid aa 22 bb 26 cc 开发者_运维技巧 28
post_table :
id content 26 abc 28 cdf 22 fds
and I wanna select from post_table with result of search in tag_table
my script : first
SELECT postid FROM `tag_table` WHERE `tag` LIKE '%aa%'
and put results in array then run a sql again
foreach ($postids as $key => $post_id) {
$sql .= "`id` = $post_id or";
}
and $sql is
SELECT * FROM `post_table` WHERE `id` = 22 or etc
and I wanna do it with one sql code is it possible ?
You can use a subquery and IN
statement like this:
SELECT *
FROM `post_table`
WHERE `id` IN (SELECT `postid`
FROM `tag_table`
WHERE `tag` LIKE '%aa%')
精彩评论