tags:

views:

524

answers:

3

Right now I'm retrieving data from my database as follows:

SELECT id, UNIX_TIMESTAMP(cdate) as myunixdate, permalink, title FROM mytable

But I would like to do it as follows, but it doesn't work.

SELECT *, UNIX_TIMESTAMP(cdate) FROM mytable

My question is, how can I combine UNIX_TIMESTAMP without having to specify all the other fields?

+2  A: 
SELECT *, UNIX_TIMESTAMP(cdate) AS my_time_stamp FROM mytable
Itay Moav
+1  A: 

It works for me in MySQL 6, Are you sure the second query is the one you really try? What version of mysql do you use?

nightcoder
+3  A: 

Are you sure you didn't try this?

SELECT UNIX_TIMESTAMP(cdate), * FROM mytable

This won't work as the * has to come first:

SELECT *, UNIX_TIMESTAMP(cdate) FROM mytable

Aliasing it will make it easier to reference in your code:

SELECT *, UNIX_TIMESTAMP(cdate) AS cdate_timestamp FROM mytable
Greg