[英]merge two query into one single query in sql
In my file there is already one query name query1
and I write another query name query2
. 在我的文件中已经有一个查询名称
query1
,我写了另一个查询名称query2
。 The o/p of both query is userid
. 两个查询的o / p是
userid
。 Now I want to find the common userid
from these two queries. 现在,我想从这两个查询中找到通用的
userid
。 So is there any function for that? 那有什么功能吗?
The array_intersect()
function generates an error. array_intersect()
函数生成错误。
Use a JOIN 使用加入
$query1 = "SELECT userid FROM table1";
$query2 = "SELECT userid FROM table2 WHERE something = 10";
$joinQuery = "
SELECT a.userid
FROM ($query1) AS a
JOIN ($query2) AS b
ON a.userid = b.userid";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.