sql - MySQL select unique record from a joint table that have duplicated referencing entry -
how display table not match result in sec table.
eg: want display each name in (table a) not have record type 1. note 'ken' have 2 log entry. 1 each type 1 , type 2. result should display john , genius
table a - name
+-----+--------+ | nid | name | +-----+--------+ | 1 | ken | | 2 | john | | 3 | genius | +-----+--------+
table b - log (each name may have multiple entry)
+------+-----+ | type | nid | +------+-----+ | 1 | 1 | | 2 | 1 | | 2 | 2 | +------+-----+
expected result
| nid | name | +-----+--------+ | 2 | john | | 3 | genius |
all have sort of records type='1' in subquery
select name tablea nid not in (select nid tableb type='1')
mysql sql database-design relational-database
No comments:
Post a Comment