Home > Backend Development > PHP Tutorial > mysql in 有关问题

mysql in 有关问题

WBOY
Release: 2016-06-13 13:08:54
Original
915 people have browsed it

mysql in 问题
数据库里有如下数据:

person表
id name 
1 zhangsan
2 lisi

SQL code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
select * from person where id in (1,2,2,2,2);

Copy after login


以上查询只能得到 1,2的数据,如下
id name 
1 zhangsan
2 lisi
我想得到重复的2的数据,如下,该怎么做啊谢谢
id name 
1 zhangsan
2 lisi
2 lisi
2 lisi
2 lisi

------解决方案--------------------
select * from person where id =1
union all
select * from person where id =2
union all
select * from person where id =2
union all
select * from person where id =2
union all
select * from person where id =2
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template