Reputation: 7905
Let's say I am going to fetch all records of table T1
. Also, I need to have access to min
and max
date value of records.
I may do that using two queries:
select * from T1 ;
select min(created_at) as min_date,max(created_at) as max_date from T1;
This is two separate queries , but is it possible to have them in one query?
I mean all records plus min and max value of a specific column.
Upvotes: 2
Views: 49
Reputation: 1203
SELECT * FROM `T1` JOIN (SELECT MIN(`created_at`) AS min_date,
MAX(`created_at`) AS max_date FROM `T1` ) AS temp
Upvotes: 0
Reputation: 204854
select *,
(select min(created_at) from T1) as min_date,
(select max(created_at) from T1) as max_date
from T1;
Upvotes: 3