mysql - Get everything from table, but if network_id is 9, only take 2 of them -
1st
select b.*, network_9.*, c.id click `banners` b, ( select id `banners` b left join `clicks` c on b.id = c.banner_id , c.user_id = 1 b.`network_id` = 9 , b.`status` = 1 , b.`type` in(1, 2) , c.`id` null limit 2 ) network_9 left join `clicks` c on b.id = c.banner_id , c.user_id = 1 b.`network_id` not in(network_0) , b.`status` = 1 , b.`type` in(1, 2) , c.`id` null limit 0, 10
2nd
select b.*, c.id click `banners` b left join `clicks` c on b.id = c.banner_id , c.user_id = 1 b.`status` = 1 , b.`type` in(1, 2) , c.id null limit 0, 10
i'm trying rows banners, if network_id 9, take 2 of them, , still others.
the 1st attempt somethin tried, failed.
and 2nd basic sql, takes rows, doesn't check on network_id
my first , realy simple aproche is:
- select rows banner network_id not equal 9 select
- select rows banner network_id equal 9 , limit them 2
second aproche be: first try: subselect ids of rows banner network_id equal 9 , limit them 2. main select rows allow rows dont having network_id equal 9 or inside subselect
select * banner id in (select id banner network_id = 9 limit 2) or network_id != 9
Comments
Post a Comment