Announcement

Collapse
No announcement yet.

select abfrage

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • select abfrage

    Hallo,

    wie kann ich alle object_id(s) selektieren, die bestimmte variablen und werte haben.

    Code:
    Tab1:
    object_id                variable_id            value
       
    1				A		 10
    1				B		 11
    1				C		 12
    1				F		 77
    2				A		 10
    2				B		 11
    2				W		 333
    3				A		 12
    3				B		 22
    3				C		 25
    4				B		 55
    4			        F		 56
    4				D		 124
    6				E		 44

    Bsp:

    Code:
    select object_id from Tab1 where (variable_id = 'A' and value = '10') and (variable_id = 'B' and value = '11') and (variable_id = 'C' and value = '12')
    Ich habe es mit Klammern visuell gezeigt was ich meine, ich möchte bestimmte variable_id mit bestimmten value verknüpfen. Es kann gut sein, dass ich 100 solche variablen so verknüpfen muss.

    Grüße

  • #2
    Hallo rob35,

    die kombinierten Bedingungen untereinander mit AND verknüpft geht schon mal gar nicht; kein Datensatz kann gleichzeitig alle Bedingungen erfüllen => OR Logik.

    [highlight=SQL]
    select object_id
    from Tab1
    where (variable_id = 'A' and value = '10')
    OR (variable_id = 'B' and value = '11')
    OR (variable_id = 'C' and value = '12')
    [/highlight]
    Olaf Helper

    <Blog> <Xing>
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    Wenn ich denke, ist das ein Fehler und das beweise ich täglich

    Comment


    • #3
      Originally posted by O. Helper View Post
      Hallo rob35,

      die kombinierten Bedingungen untereinander mit AND verknüpft geht schon mal gar nicht; kein Datensatz kann gleichzeitig alle Bedingungen erfüllen => OR Logik.

      [highlight=SQL]
      select object_id
      from Tab1
      where (variable_id = 'A' and value = '10')
      OR (variable_id = 'B' and value = '11')
      OR (variable_id = 'C' and value = '12')
      [/highlight]
      Das weiß ich aber ich muss es hinkriegen, leider..... ich muss alle object_id's auswählen, die alle variablen und dazugehörigen Werte besitzen. Ich habe schon mit "UNION" versucht aber leider kann ich nur 2 abfragen damit bedienen:

      select object_id from Tab1 where variable_id = 'a' and value='10'
      UNION
      select object_id from Tab1 where variable_id = 'b' and value='11'
      UNION
      select object_id from Tab1 where variable_id = 'c' and value='12'

      das dritte select wird einfach ignoriert.

      Comment


      • #4
        Hallo Zusammen,

        die Lösung ist INTERSECT:

        select object_id from Tab1 where variable_id = 'a' and value='10'
        INTERSECT
        select object_id from Tab1 where variable_id = 'b' and value='11'
        INTERSECT
        select object_id from Tab1 where variable_id = 'c' and value='12'

        Danke für Eure Hilfe

        Comment

        Working...
        X