mysql - SQL Selecting From One Table With Multiple Where Clauses -


searching high , low answer 1 , having no luck. i'm sure can't complicated think is.

i have 1 table titles , codes. codes unique , can have more 1 titlecode. want able select titles have codes list.

 titles                        codes  -----------------------------------  book1                         001  book2                         010  book2                         020  book2                         021  book3                         030  book3                         040 

so want able return titles have codes 020 , 021. or whatever list. in case return book2 title has 2 codes.

i tried

 select titles table codes = 020 , codes = 021  

but returned 0 results , see why. no row contains more 1 codes entry

 select titles table codes = 020 or codes = 021  

returns titles either. i've been trying use group , subquery try , having no luck. can please? in advance

in order data you're looking need use self-join on table:

select * table t1 join table t2 on t1.title = t2.title t1.codes = '020' , t2.codes = '021' 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -