There is a table with several fields, key fields for the task:
card_id
payment_date

There are several lines with the same card_id and different payment_date values
I need to select only those card_id which do not have payment_date = NUll in one line.
If at least one line with card_id has the value payment_date = NULL, do not output such values.
http://sqlfiddle.com/#!9/535867/1 is the link to the finished table for experiments.

    2 answers 2

    If you need records, then so:

    SELECT * FROM orders where card_id not in (select card_id from orders where payment_date is null) 

    If only card_id, then:

     select card_id from orders group by card_id having sum(if(payment_date is null,1,0))=0; 

    http://sqlfiddle.com/#!9/fbdba/4

    • first works .. - Durrasell
    • the second one also works .. thanks - Durrasell

    If you just need to select all entries for which payment_date is not NULL, then:

     SELECT * FROM table WHERE payment_date IS NOT NULL; 

    If you want to select exactly when dialing the same (grouped by card_id) which do not have an empty payment_date, then

      SELECT card_id, payment_date FROM orders GROUP BY card_id HAVING COUNT(IF (payment_date IS NOT NULL, NULL, 1))=0; 

    HAVING allows you to impose a condition on the group.

    • It did not work .. it still produced one line out of two .. even with HAVING - Durrasell
    • @Durrasell sorry, wrong :) Try the modified query with COUNT from my answer. - Firepro
    • I'll try now - Durrasell
    • It works thanks - Durrasell