Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Złączenie 3 tabel
Kshyhoo
post
Post #1





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Myślę i myślę i nie mogę skumać. Otóż:
  1. users
  2. id | name
  3. --+-------------
  4. 1 | Novak
  5. 2 | Kovalski
  6. 3 | Cebula
  7.  
  8. adventure
  9. id | name
  10. --+-------------
  11. 1 | PO
  12. 2 | PiS
  13.  
  14. drops (przechowywane ID i czas)
  15. id | adv | user1 | user2 | user3 | datetime
  16. ---+-----+-------+-------+-------+-----------
  17. 1 | 1 | 1 | 3 | 2 | 1473542311
  18. 2 | 2 | 2 | 3 | 1 | 1473600401

Chciałbym osiągnąć:
  1. id | adv | user1 | user2 | user3 | datetime
  2. ---+-----+----------+----------+----------+-------------
  3. 1 | PO | Novak | Cebula | Kovalski | 1473542311
  4. 2 | PiS | Kovalski | Cebula | Novak | 1473600401

Moje zapytanie znajduje ID a nie nazwy:
  1. SELECT
  2. d.id,
  3. d.adv,
  4. d.user1,
  5. d.user2,
  6. d.user3
  7. FROM drops d
  8. LEFT JOIN users u ON u.id=d.id
  9. LEFT JOIN adventure a ON a.id=d.id
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sankalppatil732
post
Post #2





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 14.10.2016

Ostrzeżenie: (10%)
X----


Here is a general SQL query syntax to join three or more table. This SQL query should work in all major relation database e.g. MySQL, Oracle,

SELECT t1.col, t3.col FROM table1 join table2 ON table1.primarykey = table2.foreignkey
join table3 ON table2.primarykey = table3.foreignkey


Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 15.10.2025 - 23:48