dauruk0512 Posted November 3, 2015 Share Posted November 3, 2015 Hello again, i want ask about query mysql here is my demo i have data products which recored all products in some area has store, then as users select product by id but also want to see where store avaiable product SELECT * FROM li_product_post a where a.product_toko=(select t.product_toko from li_product_post as t where t.id_product_post='14') by this query yes i can see all products where store avaiable but i want product selected in the top not bottom, if add up order by desc it also give me error if there are products has high values, what should i write query to get product in the top then others in bottom product_toko in english (Store product) Thanks in advance, Freddy Sidauruk Link to comment Share on other sites More sharing options...
Ingolme Posted November 3, 2015 Share Posted November 3, 2015 You can add ORDER BY at the end of the query. Link to comment Share on other sites More sharing options...
dauruk0512 Posted November 4, 2015 Author Share Posted November 4, 2015 did you mean like this moderator ? SELECT * FROM li_product_post a where a.product_toko=(select t.product_toko from li_product_post as t where t.id_product_post='14' order by t.id_product_post desc) let me assume you have a lot data, then you clicked then you get detail product. as your advice add order by in the last sub query, how about data with highest id_product_post ? if your advice will happend like this, users click product then the detail product is with the highest id_product_post ? *Hi moderator my langunge can you understand cause i have been learn communicate in english as long as programmers ? thanks a lot moderator Link to comment Share on other sites More sharing options...
Ingolme Posted November 4, 2015 Share Posted November 4, 2015 I would put the ORDER BY clause outside of the sub-query. SELECT * FROM li_product_post AS aWHERE a.product_toko = ( SELECT t.product_toko FROM li_product_post AS t WHERE t.id_product_post = 14)ORDER BY a.id_product_post DESC Link to comment Share on other sites More sharing options...
dauruk0512 Posted November 5, 2015 Author Share Posted November 5, 2015 But the result could be wrong, why because i have a lot of data, how about if product id='20' in other hand still has highest id so automatically the highest id will be the top 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