select all row except those specified in the subquery

I make a selection on request and it behaves correctly.

SELECT t1.id, MIN(t1.rate) 
FROM offers AS t1 
WHERE t1.stock > 0 
GROUP BY t1.ean;

AS soon as I nest it in another query, then the difficulty arises that WHERE NOT IN expects one column, but I need to keep MIN for GROUP BY to be preserved.

Here is query:

SELECT t2.id, t2.name, t2.ean 
FROM offers AS t2 
WHERE t2.id NOT IN (SELECT t1.id, MIN(t1.rate) 
                    FROM offers AS t1 
                    WHERE t1.stock > 0 
                    GROUP BY t1.ean);

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

So here is answer:

SELECT t1.id 
FROM offers AS t1 
WHERE  t1.id NOT IN (
    SELECT f.id
    FROM (SELECT 
            ean,
            Min(net_price) AS minprice,
            stock
          FROM offers
          GROUP  BY ean
         ) 
    AS x INNER JOIN offers 
     AS f ON f.ean = x.ean AND f.net_price = x.minprice);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x