hello master around the world, im here again with a problem 😀
now i wanna ask something simple for you but really I’m new on programming and sql, so need more learn.
ok, lets to the problem. I have some sql query like this
SELECT
eu_product.*,
eu_shop_display.display_name as dname,
eu_product_img.image_url as img
FROM eu_product
INNER JOIN eu_product_img on eu_product_img.product_id = eu_product.product_id
INNER JOIN eu_shop_display on eu_shop_display.display_id = eu_product.product_display
where eu_product.publish=1
and eu_product.shop_id=1
and eu_product.product_display IN (select display_id from eu_shop_display where parent_id=1)
or eu_product.product_display = 1
GROUP BY eu_product.product_id
ORDER BY eu_product.product_id DESC LIMIT 0, 10
The problem is in
INNER JOIN eu_product_img on
eu_product_img.product_id =
eu_product.product_id
the table seen like this

I need to using Order ASC on field “listing”.
is SQL query can use two order by, or can adding order by in inner join ? i try adding
ORDER BY eu_product.product_id DESC, eu_product_img.listing ASC
but its not working 🙁
maybe someone can explain how its work.
UPDATE
.< maybe i’ll make simple query
this product table

this product_img table

and this a result

but the ” eu_product_img.listing ASC ” not run correctly 🙁
i need the listing on product_id 1 is 1 not 4
see the table product_img
i need run the product_img.listing order ASC first before joined it.
the correct query is like this
SELECT eu_product.product_id,
(select img.listing from eu_product_img as img where img.product_id = eu_product.product_id order by img.listing ASC limit 1 ) as listing
FROM eu_product
where eu_product.shop_id=1
or eu_product.product_display = 2
GROUP BY eu_product.product_id
ORDER BY eu_product.product_id DESC LIMIT 0, 20
so it cannot using inner join ?
thanks before.
Regard,
Stecy
It is working. You see from the screenshot that they are first ordered by product_id and then by listing. If you just want to order by listing, then do
ORDER BY eu_product_img.listing ASC. If you want to order by listing then product, reverse your order by statements.Order by accepts multiple statements, but your results will be ordered in the order you specify the order statements 😉 So, if listing is first, results are ordered by listing first, etc.