Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SQL]Sortowanie wyników w zapytaniu
trifek
post 6.01.2019, 20:25:18
Post #1





Grupa: Zarejestrowani
Postów: 340
Pomógł: 0
Dołączył: 28.09.2015

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


Witam serdecznie.
Mam takie zapytanie:
  1. SELECT A.*, B.surname, B.name , C.url_address, (SELECT CONCAT(file_path, '/', file_name) AS image FROM psUploadedFiles B WHERE enum = 3 AND category = A.id_user ORDER BY number ASC LIMIT 1) AS image2 , (SELECT CONCAT(file_path, '/', file_name) AS image FROM psUploadedFiles B WHERE enum = 3 AND category = A.post_id ORDER BY number ASC LIMIT 1) AS image FROM psPosts A LEFT JOIN psUserDetails B ON B.id_user = A.id_user LEFT JOIN psUser C ON C.id_user = A.id_user WHERE A.enable = '1' AND ( A.id_user=21 OR ( A.id_user = '7' OR A.id_user = '1' OR A.id_user = '5' ) ) ORDER BY date DESC LIMIT 0 , 25 ;



W tabeli psPosts mam kolumnę subscriptions_date (zawierającą datę w formacie yyyy-mm-dd).
subscriptions_date - data do kiedy post będzie promowany.
W jaki sposób mogę posortować wyniki w taki sposób, ażeby na górze były posty zawierające subscriptions_date aktualną lub przyszłą datę (czyli promowane), a pod spodem pozostałe posty?
Go to the top of the page
+Quote Post
trueblue
post 6.01.2019, 20:28:33
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


  1. ORDER BY subscriptions_date>=CURDATE() DESC, subscriptions_date DESC


--------------------
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: 23.04.2024 - 18:20