I’m stuck on a MySQL query and don’t know what I’m doing wrong (using MySQL 5.0.88).
Here is my Query:
SELECT b.some, b.thing, bt.else AS liefdatum_gewuenscht, bt.bar
FROM btable AS b
LEFT JOIN bschedule AS bt
ON bt.key= b.key
AND bt.type = b.type
WHERE
b.entry_from IN (1,2,3,4)
AND b.`status` = "2"
AND b.date >= 20120718
LIMIT 1,10
The query should return a single record, but the check for b.status causes an empty response, although the record in question has a status of 2 with 2 being a CHARfield.
If I comment out the line it returns the correct record, however I would like to know what I’m doing wrong?
Can anyone give me hint?
Thanks!
EDIT
After some more testing I think it b.status isn’t the problem, because if I use any other column and value from the record in question it also return nothing.
E.g. the record will have columns
==== no ===== written_by =====
1111 john smith
so putting in:
AND b.no = 1111 OR b.written_by = "john smith"
also return an empty resultset.
EDIT2
Here is a sample dataset and the query. I left out the LEFT JOIN because it doesn’t make any difference:
SELECT b.*
FROM bk AS b
WHERE 1
AND b.entry_from IN ( 9900000002985 )
AND b.`status` = "2 "
AND b.bestelldatum >= 20120718
LIMIT 1,10
Table:
CREATE TABLE `bk` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`entry_from` VARCHAR(13) NULL DEFAULT NULL,
`placed_at` VARCHAR(13) NULL DEFAULT NULL,
`type` VARCHAR(2) NULL DEFAULT 'SF',
`no` VARCHAR(35) NULL DEFAULT NULL,
`date` DATE NULL DEFAULT NULL,
`written_by` VARCHAR(35) NULL DEFAULT 'Händler',
`status` VARCHAR(3) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;
hm… how to paste a record… this is the record in question
id = 985
entry_from = 9900000002985
placed_at = 9900000003005
type = SF
no = 11
date = 2012-07-19
written_by "Fachhändler"
status = 2
Try
LIMIT 0,10instead. That should work.Since it’s a CHAR type comparison, you may want to use LIKE function or STRCMP function instead of = operator.