|
SQL baze podataka - Sponzor: Baze-Podataka.net MySQL, MSSQL, Oracle, Access, ODBC. Ako imate problem brže i preciznije ćete dobiti odgovor ako priložite strukturu tabela ili skript koji kreira tabele i puni ih test podacima umesto što to problem opisujete samo rečima. Sponzor: Baze-Podataka.net - Blog o bazama podataka |
|
Alati teme | Način prikaza |
28. 02. 2006. | #1 |
novi član
Na probnom radu
Datum učlanjenja: 28.02.2006
Poruke: 10
Hvala: 1
2 "Hvala" u 2 poruka
|
Problem sa dupliranjem nekih rezultata u SELECT DISTINCT ... LEFT JOIN upitu
Pozdrav,
Imam sledeci problem, SELECT DISTINCT upit sa vise LEFT JOIN -a duplira neke rezultate na verziji mysql -a 3.23.58, dok na verziji 3.23.56 radi ocekivano (kako bi ja hteo ) Evo upita: SELECT DISTINCT (cs_update_queries.reference_number) FROM cs_update_queries, cs_update_draft_stage, cs_listing_numbers, cs_personal_info, cs_personal_info a LEFT JOIN cs_listing_info ON cs_listing_info.property_id = cs_update_queries.property_id LEFT JOIN cs_rental_info ON cs_rental_info.property_id = cs_update_queries.property_id LEFT JOIN cs_appraisal_info ON cs_appraisal_info.property_id = cs_update_queries.property_id LEFT JOIN cs_personal_info l ON l.person_id = cs_listing_info.assigned_to LEFT JOIN cs_personal_info r ON r.person_id = cs_rental_info.assigned_to LEFT JOIN cs_personal_info ap ON ap.person_id = cs_appraisal_info.assigned_to WHERE cs_update_queries.completed = '0' AND cs_update_queries.reference_number = cs_update_draft_stage.reference_number AND cs_update_queries.property_id = cs_listing_numbers.listing_id AND cs_update_queries.submitter_id = cs_personal_info.person_id AND a.person_id IN ( 0, 11837, 11668, 11658, 11921, 11652, 11675, 16580, 11665, 12485, 11679, 11672, 11666, 11688 ) AND ((l.person_id = a.person_id OR cs_listing_info.assigned_to = 0) OR (r.person_id = a.person_id OR cs_rental_info.assigned_to = 0) OR (ap.person_id = a.person_id OR cs_appraisal_info.assigned_to = 0)) AND cs_update_draft_stage.status = 'waiting' AND (field_name NOT IN ('assigned_to', 'present_status', 'listing_price', 'date_sold', 'selling_price', 'buyer_id', 'price_text_id', 'rental_status') AND table_name <> 'cs_agency_info' AND (field_name <> 'status' OR table_name <> 'cs_listing_info')) AND office_id IN ( 0, 2, 1, 8, 6 ) ORDER BY cs_update_queries.date LIMIT 10 , 10 ovo su rezultati na 3.23.56: nema duplikata 11665_20051220085047 11688_20051230162313 11665_20060106140929 11837_20060125114140 16580_20060125144715 11672_20060125162818 11672_20060126143555 11672_20060127121658 11672_20060127125540 11672_20060127130022 ovo su rezultati na 3.23.58: 11672_20060127131244 11672_20060130103227 11672_20060130104337 11672_20060130104643 11672_20060130104643 11672_20060130104908 11672_20060130111706 11672_20060130111706 11672_20060130111706 11675_20060201104657 Jel' ima neko ideju zasto se ovo desava? Inace, na prvoj strani LIMIT 0, 10 nema ponavljanja. |
28. 02. 2006. | #2 | |
Knowledge base
Wrote a book
Datum učlanjenja: 07.06.2005
Lokacija: Neđe ođe...
Poruke: 1.197
Hvala: 339
688 "Hvala" u 178 poruka
|
Ovako, na brzinu: Vidi duplira li kad izbacis "ORDER BY" iz upita. Ako ti daje rezultat kako treba, vidi ovo:
http://dev.mysql.com/doc/refman/5.0/...imization.html Citat:
__________________
Чак Норис може да си ги врзе врвките на чевлите со стапалата. |
|
28. 02. 2006. | #3 |
novi član
Na probnom radu
Datum učlanjenja: 28.02.2006
Poruke: 10
Hvala: 1
2 "Hvala" u 2 poruka
|
Hvala puno,
nema duplikata kad izbacim ORDER BY, pogledacu dati link. |
01. 03. 2006. | #4 |
novi član
Na probnom radu
Datum učlanjenja: 28.02.2006
Poruke: 10
Hvala: 1
2 "Hvala" u 2 poruka
|
Pogledao sam link, DISTINCT se smatra nekom vrstom specijalnog slucaja GROUP BY,
da bi zadrzali sortiranje, u upit se dodaje GROUP BY po DISTINCT vrednosti, a zatim ORDER BY. upit konacno izgleda ovako: SELECT DISTINCT (cs_update_queries.reference_number) FROM cs_update_queries, cs_update_draft_stage, cs_listing_numbers, cs_personal_info, cs_personal_info a LEFT JOIN cs_listing_info ON cs_listing_info.property_id = cs_update_queries.property_id LEFT JOIN cs_rental_info ON cs_rental_info.property_id = cs_update_queries.property_id LEFT JOIN cs_appraisal_info ON cs_appraisal_info.property_id = cs_update_queries.property_id LEFT JOIN cs_personal_info l ON l.person_id = cs_listing_info.assigned_to LEFT JOIN cs_personal_info r ON r.person_id = cs_rental_info.assigned_to LEFT JOIN cs_personal_info ap ON ap.person_id = cs_appraisal_info.assigned_to WHERE cs_update_queries.completed = '0' AND cs_update_queries.reference_number = cs_update_draft_stage.reference_number AND cs_update_queries.property_id = cs_listing_numbers.listing_id AND cs_update_queries.submitter_id = cs_personal_info.person_id AND a.person_id IN ( 0, 11837, 11668, 11658, 11921, 11652, 11675, 16580, 11665, 12485, 11679, 11672, 11666, 11688 ) AND ((l.person_id = a.person_id OR cs_listing_info.assigned_to = 0) OR (r.person_id = a.person_id OR cs_rental_info.assigned_to = 0) OR (ap.person_id = a.person_id OR cs_appraisal_info.assigned_to = 0)) AND cs_update_draft_stage.status = 'waiting' AND (field_name NOT IN ('assigned_to', 'present_status', 'listing_price', 'date_sold', 'selling_price', 'buyer_id', 'price_text_id', 'rental_status') AND table_name <> 'cs_agency_info' AND (field_name <> 'status' OR table_name <> 'cs_listing_info')) AND office_id IN ( 0, 2, 1, 8, 6 ) GROUP BY cs_update_queries.reference_number ORDER BY cs_update_queries.date LIMIT 10 , 10 Milose, hvala na ultra brzom odgovoru |
|
|
Slične teme | ||||
Tema | Početna poruka teme | Forum | Odgovori | Poslednja poruka |
[REŠENO] Pomoc oko select mysql (valjda join na samog sebe...) | cvele | SQL baze podataka - Sponzor: Baze-Podataka.net | 1 | 17. 10. 2008. 14:31 |
IE problem sa floated div i select | Vokic | (X)HTML, JavaScript, DHTML, XML, CSS | 7 | 07. 06. 2008. 15:46 |
problem sa clear:left | ivanhoe | (X)HTML, JavaScript, DHTML, XML, CSS | 6 | 21. 03. 2007. 12:41 |
Ogranicenost nekih institucija | zark0vac | Opušteno | 22 | 21. 01. 2007. 19:25 |