Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将mysql子查询转换为联接_Mysql_Database_Join - Fatal编程技术网

将mysql子查询转换为联接

将mysql子查询转换为联接,mysql,database,join,Mysql,Database,Join,我是mysql数据库的新手,我正在尝试创建一个使用连接的查询。 我编写的当前查询需要1秒的时间来执行,我已经进行了重新搜索,并发现连接是减少执行时间的最佳解决方案 我使用的查询是: SELECT count(1) as total FROM `mytable` where pid IN ( SELECT pid FROM `maps` where `node_id` = ( SELECT nid FROM shop WHERE

我是mysql数据库的新手,我正在尝试创建一个使用连接的查询。 我编写的当前查询需要1秒的时间来执行,我已经进行了重新搜索,并发现连接是减少执行时间的最佳解决方案

我使用的查询是:

SELECT count(1) as total 
FROM `mytable` 
where pid IN (
     SELECT pid FROM `maps` 
     where `node_id` = (
          SELECT nid FROM shop 
          WHERE value = 'selling' 
            and parent = '170' 
            and  tid = 1
          )
     and  tid = 1
) 
and `pnumber` IN (
     select pnumber 
     FROM users_pro 
     where value = 'hulo' 
     and  tid = 1
)
and tid = 1
求你了,我非常感谢你的帮助


谢谢..

Hm,
限制1
订购人
。。。对我来说,这意味着“一个随机记录”,你对你的
nid
还有其他要求吗?@Wrikken没有,它只是nid的1请详细说明:如果内部查询中有2个或更多不同的
nid
,满足要求会怎么样?@Wrikken,谢谢你的回答,我只得到一个{nid}用于该内部子查询,不会超过1So,我们可以忽略那里的
限制1
SELECT count(distinct mytable.*) as total 
FROM mytable 
JOIN maps
  ON mytable.pid = maps.pid
  AND maps.tid = mytable.tid
JOIN shop
  ON maps.node_id = shop.nid
  AND shop.value = 'selling' 
  AND shop.parent = '170' 
  AND shop.tid = mytable.tid
JOIN users_pro 
  ON mytable.pnumber = users_pro.pnumber
  AND users_pro.value = 'hulo' 
  AND users_pro.tid = mytable.tid
WHERE mytable.tid=1