PDA

View Full Version : SQL Query Question


jianneng
07-20-2003, 04:19 PM
Hi, basically I have a database called books. The table (booklist) has a issue_date column (date type). According to MySQL manual, for a date like 2003-07-31, the following query will give a result of '2003':

SELECT EXTRACT(YEAR FROM "2003-07-31");

So I want to write a single SQL query that will show me a list of books issued in 2003.

My initial query looks like this:

$query1 = "SELECT * FROM booklist WHERE (SELECT EXTRACT(YEAR FROM issue_date)=2003) ORDER BY book_no ASC";

Well...syntax error...I could have easily created another column in the table called year alone, but I just want to make my life more difficult with this :D

Thanks in advance.

Lim.

Spookster
07-20-2003, 05:44 PM
is issue_date a date field?

jianneng
07-20-2003, 05:52 PM
Yes, it is.

Spookster
07-20-2003, 07:07 PM
Then why don't you just put a where clause in to pull all records greater than or equal to jan 1 2003?

WHERE issue_date >= '2003-01-01'

jianneng
07-20-2003, 07:13 PM
Hi Moderator, thanks!

I guess I put too much attention on the year "2003" itself. Never thought of using the >= or <= :thumbsup: