Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

MYSQL Pilih Tanggal MAX di dalam pernyataan bergabung

Sesuatu seperti ini...

SELECT t1.received_id
     , t1.transaction_id
     , t1.date_modified
     , l.location
  FROM transactions t1
  JOIN ( SELECT received_id, MAX(date_modified) maxmodify FROM transactions GROUP BY received_id) max_record
    ON max_record.received_id = t1.received_id 
   AND max_record.maxmodify = t1.date_modified
  JOIN locations l
    ON l.location_id = t1.location_id
  JOIN received r
    ON r.received_id = t1.received_id
 WHERE t1.received_id = '1782'
 ORDER 
    BY t1.date_modified DESC

kernelnya adalah ini...

SELECT x.*
  FROM my_table x
  JOIN (SELECT id,MAX(thing) max_thing FROM my_table GROUP BY id) y 
    ON y.id = x.id 
   AND y.max_thing = x.thing;


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. CONVERT_TZ – Cara Mengubah Zona Waktu MySQL di Query

  2. Bagaimana cara MEMESAN DENGAN SUM () di MySQL?

  3. Referensi:Apa contoh kode yang sempurna menggunakan ekstensi MySQL?

  4. SET NAMA utf8 di MySQL?

  5. MySQL Tidak Dapat Menambahkan Batasan Kunci Asing