在MySQL中,如何为给定列仅选择具有特定值的行? [英] In MySQL, how do I select only rows with certain values for a given column?
本文介绍了在MySQL中,如何为给定列仅选择具有特定值的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这张桌子:
|user_id | first_name | last_name |
----------------------------------|
| 0 | joe | smith |
| 1 | bob | jones |
| 2 | joe | black |
| 3 | mary | jeane |
| 4 | peter | parker |
我该如何选择与user_id的1
,2
和3
相对应的行的内容?我想稍后使用这些行将其内容显示在列表中.
How would I go about selecting the contents of the rows which correspond to the user_id's 1
, 2
and 3
? I want to use these rows later to display their contents in a list to the user.
推荐答案
尝试一下:
select user_id,first_name,last_name
from your_table_name
where user_id in (1,2,3);
将your_table_name
替换为实际的表名.
这篇关于在MySQL中,如何为给定列仅选择具有特定值的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文