English 中文(简体)
MySQLach Ball from NOT IN query
原标题:MySQL Beach Ball from NOT IN query

我有两点询问,每一份 no子清单都交回。

SELECT node.nid 
  FROM dpf_node AS node 
 WHERE node.type =  image  AND node.nid; 

SELECT node.nid 
  FROM dpf_node AS node, dpf_image_galleries_images AS image 
 WHERE image.image_nid = node.nid  
   AND node.type =  image 
   AND image.gallery_nid = 138;

这两项工作都是正确的。

归根结底,尽管我想要获得第一个结果清单而不是第二个结果清单中的女婴清单,但我一直在利用这一询问:

SELECT node.nid 
  FROM dpf_node AS node 
 WHERE node.type =  image  
   AND node.nid NOT IN (SELECT node.nid 
                          FROM dpf_node AS node, dpf_image_galleries_images AS image 
                         WHERE image.image_nid = node.nid 
                           AND node.type =  image  
                           AND image.gallery_nid = 138);

而此时此刻,这只是为了打上了两条ball子,使ache子停止。 我怀疑(hope)清除数据并再次着手解决数据问题,但真的希望在系统一旦出现后重新确定其头部的情况下解决实际问题。

问题回答

改为NOT EXISTS。 询问如何帮助改进业绩:

SELECT node.nid 
  FROM dpf_node AS node 
 WHERE node.type =  image 
       AND NOT EXISTS (
         SELECT 1
         FROM dpf_node AS i_node
         JOIN dpf_image_galleries_images AS image ON i_node.nid = image.image_nod
         WHERE node.type =  image 
         AND image.gallery_nid = 138
         AND i_node.nid = node.nid
       )

您还应核实您是否有适当的指数。

MySQL might be doing rather silly stuff with correlated subqueries (look at the query plan). If you just want things from the first query that are not in the second, you might get significantly better performance from a LEFT OUTER JOIN of the two, with a filter condition that filters out rows that have nulls for the second set of results.

你们应该能够用一种选择来做到这一点。 不要选择你不希望的那点,这样你就可以排除它们,而是首先选择你想要的节点。 如果图像画廊和节点之间能够存在许多关系,那么你只希望有独特的节点。 这样,它就成为一种独特的。

SELECT node.nid
FROM dpf_node AS node
JOIN dpf_image_galleries_images AS image 
    ON node.nid = image.image_nod
WHERE node.type =  image 
AND image.gallery_nid != 138

取决于贵国数据是如何提供的,以及数据有多少,这应比条款的分顺序要好得多。 更便于理解。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签