Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [mysql] wyciagniecie ostatniego rekordu wraz z GROUP BY
AndyPSV2
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 3.11.2011

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


zapytanie jakie mam:
  1. SELECT *,COUNT(*) AS cnt FROM '.PRFX.'messages WHERE _to = "'.$this->u['id'].'" GROUP BY _from ORDER BY id DESC LIMIT '.($pg*$PER_PG).','.$PER_PG.'')


  1. id _from _to date message read
  2. 1 3 1 2011-11-07 13:49:54 dasdsasaddsadsa 0
  3. 2 3 1 2011-11-07 13:50:18 newest message 0


wynik jaki dostaje:
  1. array ( 0 => array ( 'id' => '1', '_from' => '3', '_to' => '1', 'date' => '2011-11-07 13:49:54', 'message' => 'dasdsasaddsadsa', 'read' => '0', 'cnt' => '2', ), )


wynik jaki chce uzyskac:
  1. array ( 0 => array ( 'id' => '2', '_from' => '3', '_to' => '1', 'date' => '2011-11-07 13:50:18', 'message' => 'newest message', 'read' => '0', 'cnt' => '2', ), )


jak to zrobic?

kombinowalem roznie, ale nie wyszlo np.
  1. 'SELECT id,date,message,COUNT(*) as cnt FROM (SELECT MAX(date) AS date,message FROM '.PRFX.'messages WHERE _to = "'.$this->u['id'].'" GROUP BY _from ORDER BY date DESC) LEFT JOIN '.PRFX.'messages USING (date,message) LIMIT '.($pg*$PER_PG).','.$PER_PG.''
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: 30.09.2025 - 17:27