简体   繁体   English

SQL查询似乎不会影响相同的行数,添加一个count语句

[英]SQL Query seems not to affect the same number of rows, Adding a count statement

I have made a query that looks like this 我做了一个看起来像这样的查询

Query 1. 查询1。

  SELECT zlec_status.nazwa                       AS Status, 
           piorytet.nazwa                          AS Priorytet, 
           Concat(koord.imie, ' ', koord.nazwisko) AS `Koordynator`, 
           Concat(zlec_adresy.miasto, ' - ', zlec_adresy.ulica, ' ', 
           zlec_adresy.oddzial) 
                                                   AS `adres`, 
           zlec_z_dnia,zlec_id, 
           zlec_nr, 
           zlec_do, 
           zlec_ogran, 
           awizacje, 
           awizacja_na_dzien, 
           termin_zamkniecia, 
           tresc, 
           uwagi 
    FROM   zlec 
           INNER JOIN koord 
                   ON zlec.koord = koord.id 
           INNER JOIN zlec_adresy 
                   ON zlec.zlec_addres = zlec_adresy.id 
           INNER JOIN piorytet 
                   ON zlec.priorytet = piorytet.id 
           INNER JOIN zlec_status 
                   ON zlec.status_zlecenia = zlec_status.id 

And the following one which is a ordinary one 以下是一个普通的

Query 2. 查询2。

SELECT * FROM zlec;

The thing is the first one returns ( affects by executing ) 48 rows where the second query returns 103 rows. 问题是第一个查询返回(影响执行)48行,第二个查询返回103行。 What could be the possible cause of this? 这可能是什么原因?

I will also show you my dumb of the sql in case you would like to make a run on your own http://pastebin.com/cMPAtxCU . 如果您想在自己的http://pastebin.com/cMPAtxCU上运行,我还将向您展示我对sql的理解。

Subquestion - quite no point starting of with a new question for that because its also connected with the row count affect. 子问题 -毫无疑问要从新问题开始,因为它也与行数有关。

Besides I was wondering how can I get into the first query a count(*) to get the affected rows - it has to be done in sql I cannot use php code for that, probably it would be good to use a limit 1 for the count. 此外,我想知道如何进入第一个查询中的count(*)来获取受影响的行-必须在sql中完成,我不能为此使用php代码,对于它使用限制1可能会很好计数。

With INNER JOIN , if one of your other tables, koord , zlec_adresy , piorytet and zlec_status is missing a record corresponding to a record in zlec , that record in zlec will not be in the result set. 随着INNER JOIN ,如果你的其它表的一个koordzlec_adresypiorytetzlec_status缺少对应于一个记录的记录zlec ,该记录zlec不会在结果集。 If you want every record in zlec to appear, you have to use LEFT JOIN . 如果要显示zlec每条记录,则必须使用LEFT JOIN Check out: 查看:

http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/ http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/

For a pretty good explanation. 对于一个很好的解释。

With your additional inner joins rows might be eliminated. 通过附加的内部联接,可以消除行。 Have you tried adding the inner joins to your "Select * FROM zlec;"? 您是否尝试过将内部联接添加到“ Select * FROM zlec;”中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM