Question

I have used this query before:

SELECT * 
FROM stone_list 
WHERE type IN ('ALEXANDRITE','AMETHYST') 
   AND shape IN ('OVAL') ORDER BY type, shape

It worked for me in the past, only this time it does something very weird. When I have only one value for the shape IN, the query only returns results where type is ALEXANDRITE and shape is OVAL, even though there are rows where type = AMETHYST and shape = OVAL as well.

Now, when I add a second shape, e.g. shape IN ('OVAL','ROUND'), it will return values for both type = ALEXANDRITE and type = AMETHYST and for shape = OVAL and shape = ROUND (so, it works as expected).

Really trumps me.

Anyone with any ideas?

THANKS!

Était-ce utile?

La solution

There is nothing wrong with the query, so I can only assume that there is something you've overlooked or omitted from the question.

mysql> select * from stone_list;
+----+-------------+--------+
| id | type        | shape  |
+----+-------------+--------+
|  1 | ALEXANDRITE | OVAL   |
|  2 | ALEXANDRITE | ROUND  |
|  3 | BASILIC     | OVAL   |
|  4 | AMETHYST    | SQUARE |
|  5 | AMETHYST    | ROUND  |
|  6 | AMETHYST    | OVAL   |
+----+-------------+--------+
6 rows in set (0.00 sec)


mysql> SELECT * FROM stone_list WHERE type IN ('ALEXANDRITE','AMETHYST') AND shape IN ('OVAL') ORDER BY type, shape
    -> ;
+----+-------------+-------+
| id | type        | shape |
+----+-------------+-------+
|  1 | ALEXANDRITE | OVAL  |
|  6 | AMETHYST    | OVAL  |
+----+-------------+-------+
2 rows in set (0.00 sec)


mysql> describe stone_list;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| type  | varchar(50)      | YES  |     | NULL    |                |
| shape | varchar(50)      | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top