mysql - SQL: Combine TWO selects in ONE complex Query -


i have pretty complex query:

$query = "select * element_skanning yt1             join (select objekt_nr, element_nr, vart                 element_skanning                 group objekt_nr, element_nr, vart                 having count(*) > 1)             yt2 on (yt2.objekt_nr=yt1.objekt_nr , yt2.element_nr=yt1.element_nr , yt2.vart=yt1.vart)             order 2"; 

this how db looks like:

id     objekt_nr     element_nr     vart -----------------------------------------  1         1              1          blå  2         1              1          blå  3         1              1          rosa  4         1              1          kont  5         2              1          rosa  6         2              2          blå 

my excisting query give me result: 1&2 because use 3 inputs.

now i´d search third dupe. id: 3
how can result of id: 1,2,3 not 4, 5 , 6?
check should if there row same obj_nr & el_nr "blå" or "rosa" "vart" before.
so, id 3 dupe because of id: 1 & 2.
id: 2, dupe because of 1 & 3.
id: 1, dupe because of 2 & 3.

i did rewrite couple of times, guess that´s why can´t write query.
hope can understand want here?!
, how it?

if understand correctly:

select * element_skanning yt1 join      (select objekt_nr, element_nr       element_skanning       vart in ('blå', 'rosa')       group objekt_nr, element_nr       having count(*) > 1      ) yt2       on yt2.objekt_nr = yt1.objekt_nr ,          yt2.element_nr = yt1.element_nr  vart in ('blå', 'rosa') order 2; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -