Cyclone
Cyclone

Reputation: 15269

Get the min. value of the many rows in query

Its a little bit complicated, but I will try to explain as best as I can.

I got 3 tables with news data, every table as a 'date' column that contains an unix time of the posted news.

Now select all of 'date' (from 3 tables) as get the min. value of the year using PHP date: (date('Y', $year)).

More informations:

Table1(Table2, Table3) -> has some 'date' column.

Now I need to withdraw those date fields (for example) into array, so the array will look like this: array('1323433261', '1323424614', '1322454677', ...etc); and then select the min. value in the array.

Hope you understand what I'm trying to reach, in case if you don't, please comment.

Upvotes: 1

Views: 152

Answers (1)

piotrekkr
piotrekkr

Reputation: 3181

Try this

SELECT MIN(min) FROM (
  (SELECT YEAR(FROM_UNIXTIME(MIN(add_date))) as min FROM table1) 
  UNION 
  (SELECT YEAR(FROM_UNIXTIME(MIN(add_date))) as min FROM table2) 
  UNION 
  (SELECT YEAR(FROM_UNIXTIME(MIN(add_date))) as min FROM table3)
) as t

Upvotes: 4

Related Questions