Why I do get [ERR] 1052 - Column 'RECNO' in group statement is ambiguous (MySQL)
I couldn't understand why Column 'RECNO' in group statement is ambiguous
[SQL] SELECT `d`.`FATURA_DURUM` AS `FATURA_DURUM`,
`i`.`RECNO` AS `RECNO`,
`i`.`BOLGE` AS `BOLGE`,
`m`.`MUSTERI_UNVANI` AS `MUSTERI_UNVANI`,
`i`.`MUSTERI_NO` AS `MUSTERI_NO`,
`i`.`HAKEDIS_ONAY_PERSONEL` AS `HAKEDIS_ONAY_PERSONEL`,
`i`.`ISEMRI_NO` AS `ISEMRI_NO`,
`s`.`ADRES_EMAIL` AS `ADRES_EMAIL`,
`i`.`RECNO` AS `ISEMRI_RECNO`,
`i`.`SERVIS_BAS_TAR` AS `SERVIS_BAS_TAR`,
`i`.`SERVIS_BIT_TAR` AS `SERVIS_BIT_TAR`,
`i`.`URUN_CIHAZ_ADI` AS `URUN_CIHAZ_ADI`,
`i`.`URUN_MARKA_ADI` AS `URUN_MARKA_ADI`,
`i`.`URUN_MODEL_ADI` AS `URUN_MODEL_ADI`,
`i`.`ONAY_DURUM` AS `ONAY_DURUM`,
`i`.`HAKEDIS_DURUM` AS `HAKEDIS_DURUM`,
`i`.`HAKEDIS_FATURANO` AS `HAKEDIS_FATURANO`,
`i`.`URUN_SERI_NO` AS `URUN_SERI_NO`,
`s`.`FIRMA_UNVANI` AS `FIRMA_UNVANI`,
`i`.`YAPILANLAR_M` AS `YAPILANLAR`,
st.serino_count
FROM (((`isemri` `i`
left join `musteri_tan` `m` on ((`i`.`MUSTERI_RECNO` = `m`.`RECNO`)))
join `isemri_det` `d` on ((`i`.`RECNO` = `d`.`ISEMRI_RECNO`)))
join `servisler` `s` on ((`i`.`BOLGE` = `s`.`BOLGE_NO`)))
left join
(select URUN_SERI_NO as URUN_SERI_NO2, count(*) as serino_count from ISEMRI
group by URUN_SERI_NO) as st on (st.URUN_SERI_NO2 = i.URUN_SERI_NO) WHERE 1 = 1 and `i`.HAKEDIS_DURUM=0 and `i`.ONAY_DURUM != 1 and (`i`.SERVIS_BAS_TAR between '2011-02-01 00:00:00' and '2011-09-19 23:59:59' ) and `i`.BOLGE=710 group by `i`.`RECNO`,
`m`.`MUSTERI_UNVANI`,
`i`.`MUSTERI_NO`,
`i`.`ISEMRI_NO`,
`i`.`SERVIS_BAS_TAR`,
`i`.`SERVIS_BIT_TAR`,
`i`.`URUN_CIHAZ_ADI`,
`i`.`URUN_MARKA_ADI`,
`i`.`URUN_MODEL_ADI`,
`i`.`ONAY_DURUM`,
`i`.`HAKEDIS_DURUM`,
`i`.`HAKEDIS_FATURANO`
and ( (FATURA_DURUM LIKE '%ayten%' OR RECNO LIKE '%ayten%' OR FIRMA_UNVANI LIKE '%ayten%' OR MUSTERI_UNVANI LIKE '%ayten%' OR SERVIS_BAS_TAR LIKE '%ayten%' OR SERVIS_BIT_TAR LIKE '%ayten%' OR URUN_CIHAZ_ADI LIKE '%ayten%' OR URUN_MARKA_ADI LIKE '%ayten%' OR URUN_MODEL_ADI LIKE '%ayten%' OR ONAY_DURUM LIKE '%ayten%' OR HAKEDIS_DURUM LIKE '%ayten%' OR serino_count LIKE '%ayten%' OR HAKEDIS_FATURANO LIKE '%ayten%' OR URUN_SERI_NO LIKE '%ayten%' OR YAPILANLAR LIKE '%ayten%') ) order by `i`.RECNO desc
[Err] 1052 - Column 'RECNO' in group statement is ambiguous
Edit: The above code is from Navicat. Here is the error from PHP:
<br />
<b>Fatal error</b>: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'RECNO' in group statement is ambiguous' in D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Statement\Pdo.php:238
Stack trace:
#0 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Statement.php(283): Zend_Db_Statement_Pdo->_execute(A开发者_如何学Pythonrray)
#1 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Adapter\Abstract.php(467): Zend_Db_Statement->execute(Array)
#2 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Adapter\Pdo\Abstract.php(235): Zend_Db_Adapter_Abstract->query('SELECT `d`.`FAT...', Array)
#3 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\DoDb.php(260): Zend_Db_Adapter_Pdo_Abstract->query('SELECT `d`.`FAT...')
#4 D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\DoDb.php(163): DoDb::printJsonDG('SELECT `d`.`FAT...', Object(Zend_Db_Adapt in <b>D:\Programs\xampp\htdocs\www\app\httpdocs\Application\System\Library\Zend\Db\Statement\Pdo.php</b> on line <b>238</b><br />
You're having an occurrence of "RECNO" in your query without a table alias in front of it.
Seeing there are multiple tables in your query (for instance m and i) that have the field RECNO in it; probably a later RECNO (I see one in the last and, where you put OR RECNO LIKE '%ayten%'
; which might need one of those aliases.
It might be a good practice to use the aliases in front of every field at all times; it avoids these errors, and you can easily see where the fields come from :).
精彩评论