D
D
dmitryIG2017-07-28 22:05:50
SQL
dmitryIG, 2017-07-28 22:05:50

How to remove extra category from sql query?

Good evening. There is a sql query that displays the last 12 added products.

SELECT * FROM

(SELECT resource.pagetitle,resource.uri,product.id,product.price FROM `ms2_products` AS product
INNER JOIN `site_content` AS resource 
ON resource.id = product.id 
ORDER BY product.id DESC
LIMIT 12) s1

LEFT JOIN
(SELECT img.url AS thumb,img.product_id FROM `ms2_product_files` AS img
WHERE img.path LIKE "%360x270%" AND img.rank=0
ORDER BY img.product_id DESC 
LIMIT 12) s2

ON s2.product_id = s1.id
ORDER BY s1.id DESC
LIMIT 12

We get the name of the product and the url for the card in `site_content`, the price in `ms2_products`, the link to the image in `ms2_product_files`. We connect all this by id through join.
The task is to remove certain categories of goods from the output resource.parent. Tried to do it through
ON resource.id = product.id  and resource.parent !=9231
but img.urlimmediately gives NULL or tried to remove the category by reference
ON resource.id = product.id  where resource.uri not like "%price%"
which is also NULL.
Tell me how to do it right. Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Holub, 2017-07-28
@Blitzzz

And so?

SELECT resource.pagetitle, resource.uri, product.id, product.price, img.url AS thumb 
FROM `ms2_products` AS product
               JOIN `site_content` AS resource ON resource.id = product.id 
                   LEFT JOIN `ms2_product_files` AS img ON img.product_id = product.id
WHERE img.path LIKE "%360x270%" AND img.rank=0 
             AND <добавить новое условие>
ORDER BY product.id DESC
LIMIT 12

D
d-stream, 2017-07-28
@d-stream

where and desired condition

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question