Announcement

Collapse
No announcement yet.

Daten mit Foreign Key finden

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

  • Daten mit Foreign Key finden

    Hallo zusammen.

    Ich krieg da was nicht hin. Folgendes Problem....
    Ich hab ne Table:

    id,tag_id,style_id
    1,45,5
    1,46,5
    1,49,3

    Nun müsste ich alle style_id's haben die tag_id = 45 && tag_id = 46 haben.
    Wie kann ich sowas machen?

    Grüsse und danke

  • #2
    Hallo,

    2 Möglichkeiten: Join oder exists.

    select style_id from table t1 where
    t1.tag_id = 45 and exists
    (select 1 from table t2 where t2.tag_id = 46 and t1.style_id = t2.style_id);


    oder

    select distinct style_id from table t1, table t2 where
    t1.tag_id = 45 and t2.tag_id = 46 and t1.style_id = t2.style_id;

    Gruß
    Uschi

    Comment


    • #3
      Danke für die schnelle Antwort

      Hat mit der 2ten Variante super geklappt.

      Grüsse

      Comment

      Working...
      X