问题描述:

I have a table, I want selcect data from this table with condition type =1 , type =2, type =3 and each type limit by 5.

If I used the following command, 3 table join to each other ); so I have 5x5x5 = 125 record!

SELECT *

FROM

(

( select * from `question` where type = 1 limit 5) as t1 ,

(select * from `question` where type = 2 limit 5) as t2,

(select * from `question` where type = 3 limit 5) as t3

)

How can I select this data with just 1 command so I have table with 15 records?

网友答案:
(SELECT * FROM question WHERE type = 1 LIMIT 5)
UNION
(SELECT * FROM question WHERE type = 2 LIMIT 5)
UNION
(SELECT * FROM question WHERE type = 3 LIMIT 5)
网友答案:

You should use union statement

  (select * from question where type = 1 limit 5)
  UNION
  (select * from question where type = 2 limit 5)
  UNION
  (select * from question where type = 3 limit 5)
相关阅读:
Top