Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    9

    Unanswered: two querries in one

    i have this two simillar querries :

    SELECT allgestiuni.numegest, iesiri.nrdoc
    FROM ((iesiri JOIN intrari ON ((iesiri.lotid = intrari.idlot)))
    JOIN allgestiuni ON ((intrari.gestid = allgestiuni.idgest)))
    WHERE (iesiri.tipdoc= 'tvliv') AND
    (iesiri.nrdocsec like 'validat')

    and

    SELECT allgestiuni.numegest, iesiri.nrdoc
    FROM ((iesiri JOIN intrari ON ((iesiri.nrdoc=intrari.nrdoc)))
    JOIN allgestiuni ON ((intrari.gestid = allgestiuni.idgest)))
    WHERE (iesiri.tipdoc = 'tvliv') AND
    (iesiri.nrdocsec like 'validat')

    as you see the querries returns the same columns only the
    first join differs.
    I want this two querries in one querry that will display
    4 columns with data

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    select t1.numegest  as q1_numegest
         , t1.nrdoc     as q1_nrdoc
         , t2.numegest  as q2_numegest
         , t3.nrdoc     as q2_nrdoc
      from (
    SELECT allgestiuni.numegest
         , iesiri.nrdoc
      FROM iesiri 
      JOIN intrari 
        ON iesiri.lotid = intrari.idlot 
      JOIN allgestiuni 
        ON intrari.gestid = allgestiuni.idgest 
     WHERE iesiri.tipdoc= 'tvliv' 
       AND iesiri.nrdocsec like 'validat'
           ) as t1
    full outer
      join (
    SELECT allgestiuni.numegest
         , iesiri.nrdoc
      FROM iesiri 
      JOIN intrari 
        ON iesiri.nrdoc=intrari.nrdoc 
      JOIN allgestiuni 
        ON intrari.gestid = allgestiuni.idgest 
     WHERE iesiri.tipdoc = 'tvliv' 
       AND iesiri.nrdocsec like 'validat'
           ) as t2
        on t1.numegest = t2.numegest
       and t1.nrdoc    = t2.nrdoc
    ) as d
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Posts
    9

    two querries in one

    it says something like ... number of opened parantheses
    <> number of closed parantheses

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    oh yeah, i dunno why i thought i needed it, but please remove the last line
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Feb 2004
    Posts
    9
    thanks man ... it works but in this form

    SELECT t1.numegest AS q1_numegest
    , t1.nrdoc AS q1_nrdoc
    , t2.numegest AS q2_numegest
    , t2.nrdoc AS q2_nrdoc
    FROM (
    SELECT DISTINCT allgestiuni.numegest
    , iesiri.nrdoc
    FROM iesiri
    JOIN intrari
    ON iesiri.lotid = intrari.idlot
    JOIN allgestiuni
    ON intrari.gestid = allgestiuni.idgest
    WHERE iesiri.tipdoc= 'tvliv'
    AND iesiri.nrdocsec LIKE 'validat'
    ) AS t1
    FULL OUTER
    JOIN (
    SELECT DISTINCT allgestiuni.numegest
    , iesiri.nrdoc
    FROM iesiri
    JOIN intrari
    ON iesiri.nrdoc=intrari.nrdoc
    JOIN allgestiuni
    ON intrari.gestid = allgestiuni.idgest
    WHERE iesiri.tipdoc = 'tvliv'
    AND iesiri.nrdocsec LIKE 'validat'
    ) AS t2
    ON t1.nrdoc = t2.nrdoc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •