tags:

views:

87

answers:

2

I am trying to use the following query with my table:

SELECT ARTICLE_NO, USERNAME, ACCESSSTARTS, ARTICLE_NAME, date_format(str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), '%d %m %Y' ) AS shortDate FROM AUCTIONS WHERE upper(ARTICLE_NAME) LIKE '%hardy%' and subcat = 'null' ORDER BY str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), article_no limit 0, 10

This should return over 100 records. subcat is null by default. Have I marked null incorrectly, or is there a different way to return records where a column is null?

A: 

Use

subcat IS NULL

Besides that, I think you want to use:

lower(ARTICLE_NAME) LIKE '%hardy%'

because you use lowercase in the like string.

Peter Smit
Hmm, that still gives an empty result set.
Joshxtothe4
Try to remove the Like condition. If that gives still no rows, try subcat = "" (empty instead of NULL)
Peter Smit
In the latter case you need to change the values of subcat (in the table)
Peter Smit
subcat = "" works.., is this because the fieldtype is a varchar?
Joshxtothe4
It's a varchar and the value is empty, not NULL (that's different)
Peter Smit
A: 

The query should look like this:

SELECT ARTICLE_NO, USERNAME, ACCESSSTARTS, ARTICLE_NAME, date_format(str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), '%d %m %Y' ) AS shortDate 
FROM AUCTIONS
WHERE upper(ARTICLE_NAME) LIKE '%hardy%' and subcat IS NULL
ORDER BY str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), article_no limit 0, 10

Notice the subcat IS NULL in the WHERE clause.

Rodrigo Guerreiro
This still returns an empty result set
Joshxtothe4
I have to use subcat ="". I set the fields to be null in mysql however. Is it because the fieldtype is varchar?
Joshxtothe4
try this:SELECT ARTICLE_NO, USERNAME, ACCESSSTARTS, ARTICLE_NAME, date_format(str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), '%d %m %Y' ) AS shortDate FROM AUCTIONSWHERE ARTICLE_NAME LIKE '%hardy%' and (subcat IS NULL OR subcat = '')ORDER BY str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), article_no limit 0, 10
Rodrigo Guerreiro