[英]select from table with result of another sql
Is it possible? 可能吗?
tag_table : tag_table:
tag postid aa 22 bb 26 cc 28
post_table : post_table:
id content 26 abc 28 cdf 22 fds
and I wanna select from post_table with result of search in tag_table 我想从post_table中选择tag_table中的搜索结果
my script : first 我的剧本:首先
SELECT postid FROM `tag_table` WHERE `tag` LIKE '%aa%'
and put results in array then run a sql again 并将结果放入数组然后再次运行SQL
foreach ($postids as $key => $post_id) {
$sql .= "`id` = $post_id or";
}
and $sql is 和$ sql是
SELECT * FROM `post_table` WHERE `id` = 22 or etc
and I wanna do it with one sql code is it possible ? 我想用一个sql代码做它有可能吗?
You can use a subquery and IN
statement like this: 您可以使用子查询和
IN
语句,如下所示:
SELECT *
FROM `post_table`
WHERE `id` IN (SELECT `postid`
FROM `tag_table`
WHERE `tag` LIKE '%aa%')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.