SQL select according to date

I am trying to get a recordset to select all the dates in a list from a certain year (2010 or 2011). I think I am close but I can’t quite get it to work. Can anyone pointout where I am going wrong?

“SELECT FROM dates WHERE coursecode LIKE ‘MQA03’ AND start_date <‘2010-12-25’ ORDER BY start_date”;

Cheers

Dave

If in the WHERE conditions you say that start date has to be at least January 1st and at most Dicember 31th 2010, then there’s no way that query will give you start dates in 2011.

Post the query (with the two conditions I posted) you’re using again please

Don’t use SELECT * ; type out the columns you need in the SELECT clause.

A few reasons (not all) are listed here: http://www.joelango.com/2007/04/30/why-you-should-never-use-select-star/

Thanks I Did that.Very useful.
I’m ashamed to say I never knew you could test queries that way.

So now I have this code:

SELECT * FROM dates WHERE coursecode LIKE ‘MQA03’ AND start_date >= ‘2010-01-01’
AND start_date <= ‘2010-12-31’

I get results (only 2010) which is great but I seem to have more than I need. Which suggests that this part 'LIKE ‘MQA03’ is getting mixed up somewhere.

Whatever you use is OK. Just copy and paste the query and run it. It can’t give dates in 2011.

That worked.
Thanks very much . I learned a lot there.

Dave

First of all, if you don’t use wild cards (%), LIKE is useless. You can use

WHERE coursecode = 'MQA03'

And if you could give some example data, of what there is in table, what you want to extract, and what you’re getting, it might help to get clear what the problem is

This isn’t exactly the query you’re running… you aren’t selecting anything :wink:

Where did you test it. In PHPMyAdmin?

I am using Sequel Pro (Mac)
But I have PHPmyAdmin as part of MAMP

How can you test it in PHPMyAdmin?

Thanks but I tried that but it still picks up the 2011 dates from the table which is what I’m trying to prevent.
Any ideas?

AND start_date >= '2010-01-01'
AND start_date <= '2010-12-31'

Here you go:

“SELECT FROM dates WHERE coursecode LIKE ‘MQA03’ AND start_date >= ‘2010-01-01’
AND start_date <= ‘2010-12-31’ ORDER BY start_date”;