I want to create a query that will select only the last "Something" from a table (in that table we mast have a date column !) (more about this here ) example: SELECT t.transaction_id, t.name, c.comment, . . . c.datecreated FROM transactions t JOIN ( SELECT transaction_id, MAX(datecreated) as datecreated FROM transactioncomments GROUP BY transaction_id ) m ON t.transaction_id = m.transaction_id JOIN transactioncomments c ON t.transaction_id = c.transaction_id AND m.datecreated = t.datecreated
Postări
Se afișează postări cu eticheta MySql
Getting the first & Second highest number record from a table
- Solicitați un link
- X
- Alte aplicații
Let us say that we want the Second record afther the first we will have something like this : SELECT * FROM student ORDER BY Student.Name Asc LIMIT 1,1 or another example Selecting the first record showing the biggest grade in a exam for a student (just the first record) SELECT * FROM StudentGrades ORDER BY StudentGrades.Grade Desc LIMIT 0,1