There are tables

Order - idOrder , login , product , number ;

Payment - idPayment , orderId , number (the paid amount from the order in the table. Order ).

Tell me, please, SELECT queries:

  • get the Order lines (orders) that are not referenced in the Payment table;
  • get Order lines (orders) which are referenced in the Payment table;
  • get Order lines (orders) that are referenced in the Payment table under the condition that the number fields in one and second tables are not equal, and the difference between these values, i.e. o.number-p.number;
  • @rvm, According to the rules of the forum, questions should not be reduced to proposals to perform the work. - Yura Ivanov
  • @rvm, According to the rules of the forum, questions should not be limited to the decision or the completion of student assignments. Please clarify what you have done yourself and what did not work out. - Deleted
  • 1) I do it through WHERE NOT EXISTS (SELECT * FROM payment AS p WHERE p.orderId = o.idOrder) like Ok, but I wanted to check it, 2) I do it through WHERE (p.orderId = o.idOrder), like Ok too, 3 I do it through WHERE (p.orderId = o.idOrder AND p.number <> o.number), I get an incomprehensible set, so the RIGHT variant is of interest - rvm 2:58 pm

1 answer 1

Read about aggregating functions and HAVING construction.