English 中文(简体)
避免在MySQL中出现问题 que问
原标题:Avoiding a problematic nested query in MySQL
  • 时间:2010-09-05 12:17:48
  •  标签:
  • sql
  • mysql

我有这一问询,由于我自己缺乏知识,而且由于我处理q子的问询存在问题,处理过程确实缓慢。 问题是......

SELECT    DISTINCT PrintJobs.UserName
FROM      PrintJobs
LEFT JOIN Printers
ON        PrintJobs.PrinterName = Printers.PrinterName
WHERE     Printers.PrinterGroup
IN        (
              SELECT    DISTINCT Printers.PrinterGroup
              FROM      PrintJobs
              LEFT JOIN Printers
              ON        PrintJobs.PrinterName = Printers.PrinterName
              WHERE     PrintJobs.UserName= <username/> 
          );

我想避免将这个问题分成两个问题,将分局的数值合并为主要问题。

最佳回答

然而,这或许不是你所期待的,即贡献我的2%。 首先,你应该向我们展示你的图谋,确切地说,你试图以这种方式完成。 然而,根据你的看法,你没有在桌上使用数字身份识别器,而是利用斜体田来加入表格,这实际上并不是一个好的想法业绩。 同样,我也不清楚你为什么这样做:

(select PrinterName, UserName
      from PrintJobs) AS Table1

不要只是加入印刷版。 与此类似:

(select
      PrinterName,
      PrinterGroup
      from Printers) as Table1

也许我看不到这一点。 我建议你尽可能简化问答程序。 我们还告诉我们,你希望以问答方式完成,并给我们一些表象。

从答案中去除坏问题。

问题回答

你们的这种问候很简单,并不是说,如果能够处理你需要的一切,那么,像这样,就会杀害所有被nes的问道,而且速度更快。 您也可以使用<条码>EXPLAIN的指令,以了解我的方言如何回避你的询问。

SELECT    DISTINCT PrintJobs.UserName
FROM      PrintJobs

LEFT JOIN Printers ON PrintJobs.PrinterName = Printers.PrinterName
AND Printers.Username =  <username/> 
;




相关问题
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 ...

热门标签