![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 29.02.2012 Ostrzeżenie: (0%) ![]() ![]() |
Witam.
Mam problem z zapytaniem Witam Mam 3 tabele product product_lang oraz image Potrzebuje wylistować dane produktu w nich umieszczone. Tabela nr 3 zawiera zdjęcia: id zdjecia oraz id produktu. Wszystko idzie gładko do momentu az nie napotkam produktu bez zdjecia. Wtedy zostaje on pominięty poniweaż jego id nie wystapuje w kolumnie images. Korzystam z takiego zapytania. ("SELECT product_lang.id_product, product_lang.link_rewrite, product_lang.id_lang, product_lang.name, product.id_product, product.quantity, product.price, product.reference, product.active, image.id_product, image.id_image, image.position FROM product_lang, product, image WHERE product_lang.id_product = product.id_product AND product_lang.id_product = image.id_product AND product_lang.id_lang = 3 ORDER BY product_lang.id_product DESC") Naprowadzi ktoś ? |
|
|
![]() |
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 6 380 Pomógł: 1116 Dołączył: 30.08.2006 Ostrzeżenie: (0%) ![]() ![]() |
Poczytaj o LEFT , RIGHT JOIN. Zwrócą NULL dla niewystępujących produktów.
|
|
|
![]()
Post
#3
|
|
Grupa: Moderatorzy Postów: 36 557 Pomógł: 6315 Dołączył: 27.12.2004 ![]() |
tabele IMAGE dołączaj przez LEFT JOIN a to
product_lang.id_product = image.id_product ma byc w ON składni LEFT JOIN |
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 29.02.2012 Ostrzeżenie: (0%) ![]() ![]() |
czyli coś takiego ?
("SELECT product_lang.id_product, product_lang.link_rewrite, product_lang.id_lang, product_lang.name, product.id_product, product.quantity, product.price, product.reference, product.active, image.id_product, image.id_image, image.position FROM product_lang, product LEFT JOIN image ON product_lang.id_product = image.id_product WHERE product_lang.id_product = product.id_product AND product_lang.id_lang = 3 ORDER BY product_lang.id_product DESC") |
|
|
![]()
Post
#5
|
|
Grupa: Zarejestrowani Postów: 1 168 Pomógł: 126 Dołączył: 5.02.2010 Skąd: Świdnica Ostrzeżenie: (0%) ![]() ![]() |
Próbuj, jeśli nie zadziała to pisz na forum lub próbuj zmieniać.
|
|
|
![]()
Post
#6
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 29.02.2012 Ostrzeżenie: (0%) ![]() ![]() |
no ma mbłąd (IMG:style_emoticons/default/biggrin.gif)
|
|
|
![]()
Post
#7
|
|
Grupa: Zarejestrowani Postów: 1 168 Pomógł: 126 Dołączył: 5.02.2010 Skąd: Świdnica Ostrzeżenie: (0%) ![]() ![]() |
To chociaż go podaj albo znajdzie się wróżbita na forum.
|
|
|
![]()
Post
#8
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 29.02.2012 Ostrzeżenie: (0%) ![]() ![]() |
hmm bład mam taki:
Błąd:Unknown column 'product_lang.id_product' in 'on clause' .... tak wiec posprawdzam jeszcze raz |
|
|
![]()
Post
#9
|
|
Grupa: Moderatorzy Postów: 36 557 Pomógł: 6315 Dołączył: 27.12.2004 ![]() |
nie: FROM product_lang, product
a: FROM (product_lang, product) |
|
|
![]()
Post
#10
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 29.02.2012 Ostrzeżenie: (0%) ![]() ![]() |
hmm zadziałało.
jednak w przykładach dla join nawiasów nie znalazłem. Wielkie dzięki dla wszystkich pomocnych (IMG:style_emoticons/default/smile.gif) |
|
|
![]()
Post
#11
|
|
Grupa: Moderatorzy Postów: 36 557 Pomógł: 6315 Dołączył: 27.12.2004 ![]() |
Cytat jednak w przykładach dla join nawiasów nie znalazłem. Następnym razem szukaj w manualu a nie w lodówce....http://dev.mysql.com/doc/refman/5.0/en/join.html Cytat Previously, the SELECT was legal due to the implicit grouping of t1,t2 as (t1,t2). Now the JOIN takes precedence, so the operands for the ON clause are t2 and t3. Because t1.i1 is not a column in either of the operands, the result is an Unknown column 't1.i1' in 'on clause' error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for the ON clause are (t1,t2) and t3: SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3); Alternatively, avoid the use of the comma operator and use JOIN instead: SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3); Nawet komunikat błędu podali taki sam co ty miałeś. |
|
|
![]()
Post
#12
|
|
Grupa: Zarejestrowani Postów: 11 Pomógł: 0 Dołączył: 29.02.2012 Ostrzeżenie: (0%) ![]() ![]() |
zgadza się ...
dzięki |
|
|
![]() ![]() |
![]() |
Aktualny czas: 22.08.2025 - 21:53 |