interesting many-many sql join


i have 3 associated tables "a(id, val)", "b(id, val)", couple list value "ab(aid, bid, val)"



i am querying opposing b move behind values, example:



select a.* 
from middle join ab a.id = ab.aid middle join b ab.bid = b.id
where b.val = 'foo';


every b's each b a's.



and locate i'm descending removed need filter set query advantage rows wholly ab.val max any given a/b pair



e.g. i have data:



a



id   val
1 something
2 somethingelse


b



id   val
1 foo
2 bar


ab



aid  bid  val
1 1 3
1 2 2
2 1 1
2 2 4


i wish name wholly initial final rows ab given max values any a's following means query opposing b.val = 'foo' relapse wholly initial row. i don't have thought i constrain opposing wholly max val quarrel ab table.



the best i've means is



select * 
from
inner join
(select aid, bid, max(val) val ab organisation aid) ab
a.id = ab.aid
inner join b ab.id = b.id
where b.val = 'foo'


but doesn't definitely work. first, only feels wrong approach, second, advantage bad bid values. is, bid returned subquery indispensably same quarrel max(val). i trust famous organisation emanate where preference values relapse buttress specified presumably comparison organization undefined.



i wish above creates sense, i've banging conduct opposing wall past few hours over any assistance during hugely appreciated. thanks.



(for those wondering, tangible collection backend where list b phoneme table. ab wordphoneme list 'position' column. query difference finish specified phoneme. (a phoneme sound, identical use general phonetic alphabet )



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members