SQL - MYSQL One query recieving set limit on different column values -
lets have table set of different columns (offcourse),
example :
table id col1 integer(1), // 0 || 1 col2 // --||-- col3 // --||-- col4 // --||--
is possible, in 1 query select 4 rows col1=1 , select 4 rows col2=1 , select 4 rows col3=1 etc etc. think understand mean.
what have done far make 4 different queries or make 1 query , (col1 = 1 or col2=1 or... etc).
this works if limit result lets 16, might 15 rows col1=1 , maybe 1 row col2=1 , col3,col4 - no result.
so dear fellas; there way in 1 query (i think not)
select * table col1=1 limit 4 union select * table col2=1 limit 4 union select * table col3=1 limit 4 union select * table col4=1 limit 4
this 1 result 16records max. if there less 4rows certin criteria, you'll less rows. duplicates removed, resulting in less 16 rows. not different rows.
if single row col1=1 , col2=1
, might returned twice if use union all
, union
slower large datasets
Comments
Post a Comment