MySQL get mixed result from 2 queries on same table with different order
09:52 08 Aug 2015

I have two tables for a kind of social network, table A for contents and table B for likes:

TABLE A:

CREATE TABLE `A` (
`id` int(10) unsigned NOT NULL,
  `id_user` int(10) unsigned NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `path` text,
  `ext` varchar(15) DEFAULT NULL,
  `image_type` varchar(100) DEFAULT NULL,
  `link_url` text,
  `creation_date` datetime DEFAULT NULL,
  `size` float DEFAULT NULL,
  `type` int(10) unsigned DEFAULT NULL,
  `number_share` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


ALTER TABLE `A`
 ADD PRIMARY KEY (`id`), ADD KEY `id_user` (`id_user`);

And TABLE B:

CREATE TABLE B (
  `id_b` int(10) unsigned NOT NULL,
  `id_user` int(10) unsigned NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


ALTER TABLE `B`
 ADD PRIMARY KEY (`id_b`,`id_user`), ADD KEY `id_user` (`id_user`);

I'd like to retrieve from MySQL records with this order:

    1st most popular 
     1st most recent
     2nd most popular 
     2nd most recent

 

    .....

Can anyone tell me how to combine this by MySQL (if possible) or something easy to use in PHP which is not 2 different queries?

EDIT 1:

If I have this situation:

results from first select (popular):

id 
3 
5 
12 
4 
65 
2 

and results from second select (recent):

id 
100 
121 
3 

I will go to print my elements with id:

id
3 
100 
5 
121 
12 

I want that id=3 from the second query is not considered because already posted

Thanks!

php mysql