Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SQL] Zapytanie SQL
kamilos12
post
Post #1





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 20.03.2010

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


Witam, mam problem z zapytaniem, mam 3 tabele:
- torrent
- category
- subcategory

I potrzebuje wyświelić wszystkie informacje, problem pojawia się, ponieważ wszystkie 3 tabele mają kolumnę ID oraz 2 z nich posiadają kolumnę NAME,
Moje zapytanie wygląda tak:

  1. SELECT * FROM torrent AS t INNER JOIN category AS c ON (c.id = t.category) INNER JOIN subcategory AS s ON (s.id = t.subcategory) ORDER BY t.id


Ma ktoś pomysł jak zamienić np. NAME w subcategory na przykładowo NAME_SUB? Bo teraz jak wywołam np. $row['id'] to wyświetla mi się id ale kategorii.

Bardzo proszę o odpowiedź.

Ten post edytował kamilos12 18.07.2011, 21:09:03
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
toffiak
post
Post #2





Grupa: Zarejestrowani
Postów: 395
Pomógł: 80
Dołączył: 24.08.2009

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


Użyj aliasów dla kolumn
Go to the top of the page
+Quote Post
yevaud
post
Post #3





Grupa: Zarejestrowani
Postów: 471
Pomógł: 89
Dołączył: 29.07.2008
Skąd: Warszawa

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


np.
  1. SELECT c.name AS name_cat, ... , FROM ..
Go to the top of the page
+Quote Post
webdice
post
Post #4


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




Proszę poprawić tytuł tematu na zgodny z regulaminem.
Go to the top of the page
+Quote Post
kamilos12
post
Post #5





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 20.03.2010

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


Ok, dzięki (IMG:style_emoticons/default/smile.gif) Rozwiązałem to w taki sposób:

  1. SELECT *, {$config['dbprefix']}category.name AS name_cat, {$config['dbprefix']}subcategory.name AS name_sub, {$config['dbprefix']}torrent.id AS id FROM {$config['dbprefix']}torrent INNER JOIN {$config['dbprefix']}category ON {$config['dbprefix']}category.id = {$config['dbprefix']}torrent.category INNER JOIN {$config['dbprefix']}subcategory ON {$config['dbprefix']}subcategory.id = {$config['dbprefix']}torrent.subcategory ORDER BY {$config['dbprefix']}torrent.id
Go to the top of the page
+Quote Post

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: 3.10.2025 - 12:25