I have a table in Postgres called calendar
and I am trying to query the first date value stored where year=2013.
I have written the following query which works, however I am wondering if I can query the first date instead of just getting all data and limiting just to one?
SELECT date FROM calendar WHERE year=2013 ORDER BY date ASC LIMIT 1
date
column (which btw. is a horrible name for a column), then Postgres will not "get all the data". You could do something likewhere date = (select max(date) from calendar)
but that won't be more efficient. – a_horse_with_no_name 2 days agowhere year=2013
so i presume you are not using a timestamp or date column? – Fabrizio Mazzoni 2 days agoCREATE TABLE
statements) and preferably some sample data. Your PostgreSQL version should also be in every single question. – Craig Ringer 21 hours ago