There is a model "Channel"
+------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(255) | YES | | NULL | | +------------+--------------+------+-----+---------+----------------+ There is a model "Mix"
+---------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | title | varchar(255) | YES | | NULL | | | channel_id | int(11) | YES | MUL | NULL | | | on_channel | tinyint(1) | NO | | 0 | | +---------------------+--------------+------+-----+---------+----------------+ Each mix belongs to a channel.
Request to output all mixes from channel 1, 5 и 15 :
"SELECT `mixes`.* FROM `mixes` WHERE `mixes`.`on_channel` = 1 AND `mixes`.`channel_id` IN (1, 5, 15)" +------+-------------------------------------+------------+ | id | title | channel_id | +------+-------------------------------------+------------+ | 879 | It's Disco time! MILO 8 | 5 | | 882 | ElectroDiscoFunkEklektika | 1 | | 891 | Pleasure Pizza | 5 | | 953 | Elite Disco Funk | 15 | | 958 | Special mix for Cottonmouth Podcast | 5 | | 967 | Disco on the way | 1 | | 998 | okoloDISKO #9 for FLAT.FM | 15 | | 1119 | Some Funk For Your Ass | 5 | | 1267 | GET PHONKEY WITH YOU | 15 | | 1272 | Friendly Vibes Mix | 5 | +------+-------------------------------------+------------+ Question: how to make the sorting be in order channel_id = (1, 5, 15) iteratively, i.e.
+------+-------------------------------------+------------+ | id | title | channel_id | +------+-------------------------------------+------------+ | 882 | ElectroDiscoFunkEklektika | 1 | | 879 | It's Disco time! MILO 8 | 5 | | 953 | Elite Disco Funk | 15 | | 967 | Disco on the way | 1 | | 891 | Pleasure Pizza | 5 | | 998 | okoloDISKO #9 for FLAT.FM | 15 | | 958 | Special mix for Cottonmouth Podcast | 1 | | 1119 | Some Funk For Your Ass | 5 | | 1267 | GET PHONKEY WITH YOU | 15 | | 1272 | Friendly Vibes Mix | 1 | +------+-------------------------------------+------------+
"SELECTmixes.* FROMmixes` WHEREmixes.on_channel= 1 ANDmixes.channel_idIN (1, 5, 15) Problem, I couldn’t build request 3 by example. sort by these serial numbers and channel number - similar to paragraph 2 If possible, help with my example - Deepsystmrow_number() over(partition by channel_id order by id)will give you numbers 1,2,3 within one channel and if you sort by it, you will already get all 1st records (of all channels), then all 2nd etc. - Mike