开发者

return multiple row when i have multiple ids in csv format in mysql

开发者 https://www.devze.com 2022-12-30 16:07 出处:网络
i know it may be very simple query, but please help me out. i have item id 1,2,3,4 etc.... now i want to get all row regrading that item id

i know it may be very simple query, but please help me out.

    i have item id 1,2,3,4 etc.... 

now i want to get all row regrading that item id what will be mysql query?? i used IN operator but this return only one row

SELECT item_id,item_name FROM tbl_item_detail WHERE item_id IN('1,3,4')

my table structure is below

item_id | item_name |.....
  1 开发者_运维技巧    |  first    |
  2     |  second   |
  3     |  third    |
  4     |  fourth   |

. .

which operator i have to use?or what will be perfect query for this?


After firing this query, mysql would have returned two things:
1. The item_id, item_name of the row with id 1 in the tbl_item_detail table.
2. A warning after the above result like, '1 row in set, 3 warnings (0.00sec)'.

The warning message means that there was a problem in your query, and mysql could only partially understand it. Your query was:

SELECT item_id,item_name FROM tbl_item_detail WHERE item_id IN('1,3,4');

It should actually be:

SELECT item_id,item_name FROM tbl_item_detail WHERE item_id IN(1,3,4);

OR

SELECT item_id,item_name FROM tbl_item_detail WHERE item_id IN('1','3','4');

I believe the rest is self explanatory.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号