2012-03-30 23 views
5

Mam kwerendę mysql, która używa union do łączenia wielu kwerend w jeden zestaw wyników. zapytanie działa idealnie.mysql - nie można utworzyć widoku, który zawiera związek

Kiedy chcę używać tego samego zapytania do utworzenia widoku I wtedy pojawia się komunikat o błędzie:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'union select hulaminloadnumber2,deliveryid,drop1customer from localjhb where hul' at line 2 

moje zapytanie, które działa idealnie brzmi:

select hulaminloadnumber1,deliveryid,drop1customer from localjhb where hulaminloadnumber1>0 
union 
select hulaminloadnumber2,deliveryid,drop1customer from localjhb where hulaminloadnumber2>0 
union 
select hulaminloadnumber3,deliveryid,drop1customer from localjhb where hulaminloadnumber3>0 
union 
select hulaminloadnumber4,deliveryid,drop1customer from localjhb where hulaminloadnumber4>0 
union 
select hulaminloadnumber5,deliveryid,drop1customer from localjhb where hulaminloadnumber5>0 

query results

mój zapytanie do utworzenia widoku to:

create view View_LoadvsCustomer as (
select hulaminloadnumber1,deliveryid,drop1customer from localjhb where hulaminloadnumber1>0 
union 
select hulaminloadnumber2,deliveryid,drop1customer from localjhb where hulaminloadnumber2>0 
union 
select hulaminloadnumber3,deliveryid,drop1customer from localjhb where hulaminloadnumber3>0 
union 
select hulaminloadnumber4,deliveryid,drop1customer from localjhb where hulaminloadnumber4>0 
union 
select hulaminloadnumber5,deliveryid,drop1customer from localjhb where hulaminloadnumber5>0) 

ten wytwarza poniżej błąd w phpMyAdmin: error message

Zapytania są ze źle zaprojektowanym stole, więc nie powinno być żadnych problemów formatowania lub sortowania. Czy można utworzyć widok dla kwerendy związanej?

Każda rada jest doceniana.

Miłego weekendu, Ryan

+1

Wszystkie zapytania SELECT mają ten sam warunek - 'hulaminloadnumber1> 0'. Czy to jest poprawne? – Devart

+0

Witaj @Devart, masz rację, przykro mi kopie błędnego kodu. poprawi pytanie. Ten sam błąd występuje jednak przy poprawnym kodzie. Dziękujemy – Smudger

+1

O błędzie - spójrz na odpowiedź Ashwina A. Naprawi to. – Devart

Odpowiedz

23

Usuń nawiasy z definicji widoku. Udało ci się trafić na ten serwer bug.

+0

Dzięki Ashwin A, działa idealnie – Smudger

+2

Dziękuję! Dokładnie problem i rozwiązanie. Aby pomóc każdemu, kto szuka w przyszłości, był to błąd, który otrzymywałem: 'ERROR 1064 (42000): Wystąpił błąd w składni SQL; sprawdź instrukcję, która odpowiada twojej wersji serwera MySQL dla właściwej składni do użycia w pobliżu "WYBÓR UNIWERSALNEGO WYBORU ..." – dkamins

Powiązane problemy