Jump to content

Multiple order by from join table


dauruk0512

Recommended Posts

Hello guys i have some stuck about multiple join and multiple order by .

 

here i cut all field to make you understand what i feel

CREATE TABLE IF NOT EXISTS `li_product_post` (  `id_product_post` int(11) NOT NULL,  `id_user` int(11) NOT NULL,  `product_akurat` int(11) NOT NULL,  `product_tidak_akurat` int(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;INSERT INTO `li_product_post` (`id_product_post`, `id_user`, `product_akurat`, `product_tidak_akurat`) VALUES(1, 32, 5, 4),(2, 28, 1, 0),(3, 27, 0, 1),(4, 27, 2, 0),(5, 27, 0, 0);

 

i need to select data from that table which is priority

  1. Order by id_product_post desc
  2. product_akurat desc
  3. product_tidak_akurat desc
  4. group by id_user

so here is i make demo please see, the worng things i need to put id_product_post 5 in the first place not id_product_post 3 cause order by id_product_post desc the first priority, hope you guys help me !Thanks in advance

Edited by dauruk0512
Link to comment
Share on other sites

It's not necessarily to join those tables if you're only selecting and ordering from one table.

i need to put id_product_post 5 in the first place not id_product_post 3

When you group by the user it's only going to return 1 row for each user. There are 3 rows for the same user and since you're telling it to group by that field then it's only going to return one row for that user.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...