Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SQL] Wyciągniecie z tabeli nie pasujących rekordów
emeres1
post 15.02.2019, 11:20:00
Post #1





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 28.03.2010

Ostrzeżenie: (0%)
-----


hej,
mam takie dwie tabelki:

airports_list
id name
1 airport1
2 airport2
3 test
4 test1

group_travel_airports
id airport_id
1 1
2 1

Chciałbym wyciągnąć z tabeli airport_list rekordy niepasujące do group_travel_airports (test,test1).

Próbuję:
  1. SELECT DISTINCT airports_list.id, group_travel_airports.airport_id FROM group_travel_airports LEFT JOIN airports_list ON group_travel_airports.airport_id = airports_list.id WHERE group_travel_package_id = 109

Go to the top of the page
+Quote Post
viking
post 15.02.2019, 12:00:59
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


  1. WHERE group_travel_airports.airport_id IS NULL


--------------------
Go to the top of the page
+Quote Post
mmmmmmm
post 15.02.2019, 12:43:59
Post #3





Grupa: Zarejestrowani
Postów: 1 421
Pomógł: 310
Dołączył: 18.04.2012

Ostrzeżenie: (0%)
-----


  1. WHERE airports_list.id IS NULL
Go to the top of the page
+Quote Post
emeres1
post 15.02.2019, 12:47:20
Post #4





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 28.03.2010

Ostrzeżenie: (0%)
-----


Jest szansa, że się pomyliłeś? Dostaję pustą tabele z id i airport_id. Specjalnie ręcznie dodałem jeszcze jeden rekord do airports_list na wszelki wypadek:)

  1. SELECT DISTINCT airports_list.id, group_travel_airports.airport_id FROM group_travel_airports LEFT JOIN airports_list ON group_travel_airports.airport_id = airports_list.id WHERE group_travel_package_id = 109 AND group_travel_airports.airport_id IS NULL
Go to the top of the page
+Quote Post
nospor
post 15.02.2019, 12:49:51
Post #5





Grupa: Moderatorzy
Postów: 36 447
Pomógł: 6292
Dołączył: 27.12.2004




FROM ma byc po airports_list
a LEFT JOIN po group_travel_airports

Koledzy chyba do konca nie spojrzeli co miales w swoim zapytaniu


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
emeres1
post 15.02.2019, 13:04:10
Post #6





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 28.03.2010

Ostrzeżenie: (0%)
-----


To miałeś na myśli? Niestety dalej nie działa smile.gif
  1. ]SELECT DISTINCT airports_list.id, group_travel_airports.airport_id FROM airports_list LEFT JOIN group_travel_airports ON group_travel_airports.airport_id = airports_list.id WHERE group_travel_package_id = 109 AND group_travel_airports.airport_id IS NULL


Ten post edytował emeres1 15.02.2019, 13:06:03
Go to the top of the page
+Quote Post
nospor
post 15.02.2019, 13:12:33
Post #7





Grupa: Moderatorzy
Postów: 36 447
Pomógł: 6292
Dołączył: 27.12.2004




Tak, wlasnie to.

Nie mniej jednak nie rozumiem tego
group_travel_package_id = 109
skoro nigdzie nie pokazales gdzie to pole jest i co ono oznacza.

Moze pokaz CALA strukture tabel z poprawnymi danymi bo w przykladzie dane tez podales blednie. Moze tam gdzies lezy problem


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
emeres1
post 15.02.2019, 13:17:34
Post #8





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 28.03.2010

Ostrzeżenie: (0%)
-----


Od tego powinienem zacząć smile.gif Chciałbym wydostać pole TEST smile.gif



Ten post edytował emeres1 15.02.2019, 13:18:54
Go to the top of the page
+Quote Post
nospor
post 15.02.2019, 13:25:02
Post #9





Grupa: Moderatorzy
Postów: 36 447
Pomógł: 6292
Dołączył: 27.12.2004




Z tego co na szybko patrze to to:
group_travel_package_id = 109
powinno byc dodane do ON a nie do WHERE jak jest teraz.

Nie mnie jednak w tabeli group_travel_airports nie widze ID z tabeli airports_list. Czyzby tym ID bylo pole o nazwie ID? Troche dziwnie i mylaco to nadane jest w takim razie

edit, ach nie, juz widze... slepota

To tak jak mowie:
group_travel_package_id = 109
ma byc w ON


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
emeres1
post 16.02.2019, 18:46:00
Post #10





Grupa: Zarejestrowani
Postów: 72
Pomógł: 0
Dołączył: 28.03.2010

Ostrzeżenie: (0%)
-----


Działa! Bardzo dziękuję smile.gif

Bardzo mi ostatnio pomogliście, a muszę Was prosić o pomoc raz jeszcze. Morduję się już 4 godzinę, aby to samo zapytanie upchnąć do symfony.

SQL:
  1. SELECT DISTINCT airports_list.id, group_travel_airports.airport_id FROM airports_list LEFT JOIN group_travel_airports ON group_travel_airports.airport_id = airports_list.id AND group_travel_package_id = 109 WHERE group_travel_airports.airport_id IS NULL


Symfony:
  1. $qb = $this->createQueryBuilder('g');
  2. $qb->select('DISTINCT a , g')
  3. ->leftJoin('App\Entity\AirportsList','a', Join::WITH , 'a = g.airport')
  4. ->where($qb->expr()->andx(
  5. $qb->expr()->isNotNull('g.airport'),
  6. $qb->expr()->eq('g.groupTravelPackage', $id)
  7. ))
  8. ;


Ten post edytował emeres1 15.02.2019, 13:42:29
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 20.04.2024 - 04:05