S
S
snake22022-04-01 11:24:10
css
snake2, 2022-04-01 11:24:10

How to select orders from related table with condition?

There are two tables
orders
-id
-name
order_product
-id
-order_id
-importance

How to get all order records where order_product importance is either all zeros or all ones and zeros.
If all order_product importance is 1, then exclude such an order

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Neyury, 2016-08-04
@Neyury

I advise you to read this article, it describes all the horizontal and vertical centering options for inline (including inline-block ) and block elements.

A
A person from Kazakhstan, 2016-08-04
@LenovoId

codepen.io/Geyan/pen/WxgVBa
Let's say we need to add another parent block for the text , and then you will see

S
Slava Rozhnev, 2022-04-01
@snake2

Learning to use the WHERE EXISTS / NOT EXISTS construct

select 
  * 
from 
  orders 
where 
  exists (
    select 
      1 
    from 
      order_product 
    where 
      order_id = orders.id 
      and importance = 0
  );

MySQL WHERE EXISTS test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question