count - MySql: hard match on same table -


i have table containing products shop's orders

+----------------------------+ | orders_id | products_model | +----------------------------+ |   1000    | aa0000001      | |   1000    | bb0000002      | |   1000    | cc0000001      | |   1001    | aa0000001      | |   1002    | bb0000001      | |   1003    | cc0000001      | |   1004    | bb0000001      | |   1004    | aa0000001      | +----------------------------+ 

every order can have, of course, 1 or more items

i need list of orders containing items code starting aa or bb (or both) don't want list orders containing items code starting evey other code type.

example:

+-----------+ | orders_id | +-----------+ |   1001    |          |   1002    |  |   1004    | +-----------+ 

order 1000 has excluded because has 'cc' item beside 'aa' , 'bb' ones order 1003 has excluded because has 'cc' item

i started experimenting compare count of matching records , count of records every order.....but had stop...i'm sql newbie lost myself in jungle of nested queries :)

could please me?

think may require

select distinct orders_id orders ord left join (select distinct orders_id     orders     products_model  'cc%' or products_model 'dd%') ccdditems on ccdditems.orders_id = ord.orders_id ccdditems.orders_id null 

as littlebobbytables points out, if have 'ee', 'ff' etc, may want replace inner query not 'aa%' , not 'bb%'


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -