tags:

views:

64

answers:

2

I am trying to select the following query from 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 SUBCAT = 'fake' and USERNAME = 'testuser' ORDER BY 
str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), article_no limit 0, 10

I get 0 results back.

However, both

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 SUBCAT = 'fake' ORDER BY 
str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), article_no limit 0, 10

and

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 USERNAME = 'testuser' ORDER BY 
str_to_date(ACCESSSTARTS, '%d.%m.%Y %k:%i:%s'), article_no limit 0, 10

return the expected result sets. Why are they not working together?

+2  A: 

i think, that you have no result with a combination of "fake" AND "testuser"? (do you mean OR?)

Peter Miehle
+2  A: 

WHERE SUBCAT = 'fake' and USERNAME = 'testuser'

Should be:

WHERE SUBCAT = 'fake' OR USERNAME = 'testuser'

this will return both results which is what you're after right?

Edit: Sorry, misread the fields. Add the "SUBCAT" column into your queries so you can see how many occurences there are with each one and make sure the combination will produce results before applying both where clauses.

Tanner
the AND would be impossible to evaluate because it can't be both values but it could be one OR the other.
Tanner
why? I want to select all records that have the category fake belonging to the user testuser. Surely using OR will result in all the records in the fake subcategory with any user?
Joshxtothe4
Sorry, my mistake, have posted edit.
Tanner