Announcement

Collapse
No announcement yet.

Self join ?!

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

  • Self join ?!

    Es gibt eine Spalte ID und eine Spalte Datum. Gleiche ID's können in mehreren Jahren vorkommen. Nun möchte ich nur die ID's wissen welche z.B. nur im Jahr 2005 vorkommen.

    Habe bislang noch nichts brauchbares zustandebekommen.

    Vielen Dank im voraus

  • #2
    Hallo,

    das mit dem Join verstehe ich nicht ganz!?
    Warum nicht

    select id
    from tabelle
    where to_char(Datum,'YYYY') ='2005';

    ?

    Gruß

    Martin

    Comment


    • #3
      Wenn ich diese Abfrage mache bekomme ich zwar die ID's in 2005 aber ich weiss nicht ob sie nicht auch in 2006 noch vorhanden sind.
      Ich möchte ausschließlich nur IDs sehen, welche nur in 2005 vorkommen.

      Comment


      • #4
        Hallo,

        sollte sowohl mit einem SELF-Join
        [highlight=sql]
        select a.ID
        from <tabelle> a
        left join <tabelle> b on b.ID = a.ID and b.Datum <> 2005
        where a.Datum = 2005
        and b.id is null
        [/highlight]
        als auch mit einem Subselect
        [highlight=sql]
        select a.ID
        from <tabelle> a
        where a.Datum = 2005
        and not exists (
        select 1
        from <tabelle> b
        where b.id = a.id
        and b.Datum <> 2005
        )
        [/highlight]
        gehen.

        Gruß Falk
        Wenn du denkst du hast alle Bugs gefunden, dann ist das ein Bug in deiner Denksoftware.

        Quellcode ohne ein Mindestmaß an Formatierung sehe ich mir nicht an! Ich leiste keinen Privatsupport per Mail oder PN!

        Comment


        • #5
          Falk, ich wünsche dir ein frohes Fest und vielen Dank für die schnelle , super Lösung
          Gruß Rolf

          Comment


          • #6
            Originally posted by flipo View Post
            Wenn ich diese Abfrage mache bekomme ich zwar die ID's in 2005 aber ich weiss nicht ob sie nicht auch in 2006 noch vorhanden sind.
            Ich möchte ausschließlich nur IDs sehen, welche nur in 2005 vorkommen.
            Sorry,

            hatte Dich so verstanden, dass Du nur die Daten aus 2005 sehen wolltest und nicht ausschiesslich in diesen vorkommende

            Comment

            Working...
            X