Jump to content

Select data by id but get also data with same product_toko


dauruk0512
 Share

Recommended Posts

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

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

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

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
 Share

×
×
  • Create New...