Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Łączenie 2 Tablic i Sortowanie
Kwadrat
post
Post #1





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 21.04.2003

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


Mam przykladowo 2 tabele:

Tabel nr. 1 : tabela_1
  1. id | tekst | nr | czas ------------------------
  2. 0 | ble0 | 1 | 2005.03.01 15:00
  3. 1 | ble1 | 1 | 2005.03.02 15:00
  4. 2 | ble2 | 1 | 2005.03.03 15:00
  5. 3 | ble3 | 1 | 2005.03.04 15:00

Tabel nr. 2 : tabela_2
  1. id | tekst | nr | czas ------------------------
  2. 5 | ble0 | 2 | 2005.03.01 17:00
  3. 6 | ble1 | 2 | 2005.03.02 17:00
  4. 7 | ble2 | 2 | 2005.03.03 17:00
  5. 8 | ble3 | 2 | 2005.03.04 17:00

I chce zeby mi to polaczyl w jedna tabele i posegergowal razem wedlug "czas" oczywiscie dzialajac w petli czyli:

Tabel:
  1. id | tekst | nr | czas ------------------------
  2. 8 | ble3 | 2 | 2005.03.04 17:00
  3. 3 | ble3 | 1 | 2005.03.04 15:00
  4. 7 | ble2 | 2 | 2005.03.03 17:00
  5. 2 | ble2 | 1 | 2005.03.03 15:00
  6. 6 | ble1 | 2 | 2005.03.02 17:00
  7. 1 | ble1 | 1 | 2005.03.02 15:00
  8. 5 | ble0 | 2 | 2005.03.01 17:00
  9. 0 | ble0 | 1 | 2005.03.01 15:00


zrobilem cos takiego co mi wyciag dane z obu tablei w jednym zapytaniu ale cos nie chce sortowac. Dodalem tam miezy innymi "ORDER BY tabela_1.czas AND tabela_2.czas" ale nic nie dalo ;]. Wogole probowalem na wiele spospobow ale nic nie dziala tongue.gif I jak narazie jestem w kropce smile.gif

  1. SELECT
  2. tabela_1.id,
  3. tabela_1.tekst,
  4. tabela_1.nr,
  5. tabela_1.czas,
  6. tabela_2.id,
  7. tabela_2.tekst,
  8. tabela_2.nr,
  9. tabela_3.czas,
  10. FROM tabela_1, tabela_2
  11. ORDER BY {questionmark.gifquestionmark.gif}
  12. DESC


ThX

Ten post edytował Kwadrat 9.03.2005, 15:49:08
Go to the top of the page
+Quote Post
Darti
post
Post #2





Grupa: Zarejestrowani
Postów: 1 076
Pomógł: 62
Dołączył: 6.03.2005
Skąd: Wroc

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


A może tak? :
  1. SELECT id,tekst,nr,czas FROM tabela_1 UNION ALL SELECT id,tekst,nr,czas FROM tabela_2 ORDER BY czas DESC


jak wywalisz ALL to pominie duplikaty

Pozdrawiam


--------------------
The answer is out there, Neo. It's looking for you. And it will find you, if you want it to.
SERVER_SOFTWARE : Apache/2.2.4 (Win32) PHP/5.2.1
MySQL Client API version : 5.0.27
Go to the top of the page
+Quote Post
Kwadrat
post
Post #3





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 21.04.2003

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


Tylko ze duplikaty z ID, napewno sie powtorza snitch.gif wiec skasuje mi wszytsko. Ale jak tylko bede miał komputer pod ręką to sprawdze efekty i zdam relacje tongue.gif

Dzięki
Go to the top of the page
+Quote Post
Darti
post
Post #4





Grupa: Zarejestrowani
Postów: 1 076
Pomógł: 62
Dołączył: 6.03.2005
Skąd: Wroc

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


rolleyes.gif chodziło nie o duplikaty z komorek tylo duplikaty CAŁYCH wierszy


--------------------
The answer is out there, Neo. It's looking for you. And it will find you, if you want it to.
SERVER_SOFTWARE : Apache/2.2.4 (Win32) PHP/5.2.1
MySQL Client API version : 5.0.27
Go to the top of the page
+Quote Post
Kwadrat
post
Post #5





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 21.04.2003

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


No i super tongue.gif Dziala pieknie smile.gif ThX
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 Aktualny czas: 20.08.2025 - 23:52