dauruk0512 Posted October 30, 2015 Share Posted October 30, 2015 (edited) 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 Order by id_product_post desc product_akurat desc product_tidak_akurat desc 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 October 30, 2015 by dauruk0512 Link to comment Share on other sites More sharing options...
justsomeguy Posted October 30, 2015 Share Posted October 30, 2015 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 3When 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 More sharing options...
dauruk0512 Posted October 31, 2015 Author Share Posted October 31, 2015 Hi moderator yes i know in the demo i give simple to make members know what i'm feeling.it's oke, how to query to select data with multiple order by Order by id_product_post desc product_akurat desc product_tidak_akurat desc Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted November 2, 2015 Share Posted November 2, 2015 ORDER BY id_product_post DESC, product_akurat DESC, product_tidak_akurat DESC Link to comment Share on other sites More sharing options...
dauruk0512 Posted November 3, 2015 Author Share Posted November 3, 2015 thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now