Find out the order, but does not contain some goods! As long as there is a non-conforming order, it will not be displayed?

assume the data table relationship:

order order data sheet:

order_id / public_order_id

1 / AAA
2 / BBB
3 / CCC

prod goods data sheet:

order_id / prod_id

1 / 100
1 / 101
1 / 102
2 / 101
2 / 103
3 / 102
3 / 104

Front end display

AAA
BBB
CCC

when I want to exclude an order with a certain prod_id that does not display
suppose I want to rule out that the order does not display if it has prod_id 100s

the front end will exclude AAA and the rest:

BBB
CCC

if prod_id 101
is appended, only CCC will be left (because both AAA and BBB contain 100,101)

CCC

how can I judge this?

SELECT
r.public_order_id,
FROM `order` as r
JOIN `prod` as p ON p.order_id = r.order_id
WHERE p.prod_id != 100
AND p.prod_id != 101
// GROUP BY r.public_order_id

I find that if there is no GROUP BY public_order_id,
assumes how many prod_id the order has, how many public_order_id will be repeated
but if I GROUP BY public_order_id,
he will print out all the AAA,BBB,CCC, but in fact, each order has more than one prod_id, and there are 100,101
that I don"t want. So something will go wrong!

< hr >

what I want to achieve is
when there is a prod_id in the order that I don"t want, it doesn"t show
. Now, although the order has a prod_id that I don"t want, there are other goods that are not this prod_id, so it shows

again. < hr >

charge

Database structure:

clipboard.png

SQL sentence

SELECT

    r.status,
    uo.add_time,
    r.public_order_id,
    uo.order_id,
    u.name as uname,
    ss.prod_id
  FROM `user_order` as uo
  JOIN `order_record` as r ON r.order_id = uo.order_id
  JOIN `user` as u ON u.id = r.id
  JOIN `stock` as ss ON ss.order_id = r.order_id
  AND (ss.prod_id = 115
  or ss.prod_id = 120)
  WHERE r.status = ""
  AND ss.prod_id is null
Oct.26,2021

SELECT r.public_order_id,
    FROM `prod ` as p
        JOIN `order` as r ON p.order_id = r.order_id
    WHERE p.prod_id NOT IN (100,101)
    GROUP BY r.public_order_id

you can first look at the results after join to see where the problem lies
, but you can look up
select public_order_id from order_d

like this.
where order_d.order_id not in(
    select order_id from prod
    where prod.prod_id = "100" or prod.prod_id = "101"
);

try this

SELECT r.public_order_id
  FROM `order` as r
  LEFT JOIN `prod` as p ON p.order_id = r.order_id and (p.prod_id = 100 or p.prod_id = 101)
 WHERE p.prod_id is null


clipboard.png

clipboard.png

clipboard.png


try

select o.public_order_id from order o where not exists (select p.order_id from prod p where (p.prod_id=100 or p.prod_id=101) and p.order_id=o.order_id group by p.order_id)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c24e83-3373f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c24e83-3373f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?