Joining these two queries

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Joining these two queries

    Can anyone help me to join Query 1 to Query 2

    cheers
    rob

    Query 1
    -------------

    SELECT * FROM

    (SELECT COUNT(DISTINCT RLID) AS NoBooked, SUM(PlacesNo) AS NoPlacesTaken,
    RL.EID, V.EventPlaces, CAST (V.EventPlaces-SUM(PlacesNo) AS Int) AS
    PlacesAvailable
    FROM tbl_ep_Returns_List RL, tbl_ep_Venue V
    WHERE RL.Status <= 2 AND RL.EID = 4 AND RL.EID = V.EID
    GROUP BY RL.EID, V.PlacesMax, V.PlacesMin, V.EventPlaces)

    tbl_tmp1

    WHERE EID = 4

    Query 2
    ---------------

    SELECT EID, Status AS TheStatus, RLID, PlacesNo, FName, LName, Organisation,
    RecievedDate, JobRole
    FROM dbo.tbl_ep_Returns_List
    WHERE RLID = 22


    Robert J Egan Guest

  2. Similar Questions and Discussions

    1. Help needed with Joining 2 Queries together
      hi all. i've got the following two queries and i'd like to combine them into one, and i just can't figure it out. hoping someone here can get the...
    2. Joining three tables
      Hello all, I am having a bear of a time trying to join three tables in Sybase. Here is the query...... select DISTINCT(appl.ag_id),...
    3. Queries Of Queries Single Quote Problem
      When using queries of queries I'm having the following issue. Select Company_ID From qry_MyQuery Where Company_NM = 'MyString''s' <----...
    4. Joining Paths or joining two shapes
      Hi, I have drawn threeleaves with the pen tool (closed paths). I would like to join these leaves to make a flower into which I want to place an...
    5. help with joining 2 images together
      I would like to know if anyone can suggest a way of joining 2 images side by side without a straight line between the images. Like feathering...
  3. #2

    Default Re: Joining these two queries

    Assuming this is SQL Server(what version, please?)
    Select * FROM
    (Query1) q1
    INNER JOIN
    (Query2) q2
    ON q1.<joining column> = q2.<joining column>

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From header is
    my spam trap, so I don't check it very often. You will get a quicker
    response by posting to the newsgroup.
    "Robert J Egan" <rob_j_egan@hotmail.com> wrote in message
    news:epRgTPs2DHA.2544@TK2MSFTNGP10.phx.gbl...
    > Can anyone help me to join Query 1 to Query 2
    >
    > cheers
    > rob
    >
    > Query 1
    > -------------
    >
    > SELECT * FROM
    >
    > (SELECT COUNT(DISTINCT RLID) AS NoBooked, SUM(PlacesNo) AS NoPlacesTaken,
    > RL.EID, V.EventPlaces, CAST (V.EventPlaces-SUM(PlacesNo) AS Int) AS
    > PlacesAvailable
    > FROM tbl_ep_Returns_List RL, tbl_ep_Venue V
    > WHERE RL.Status <= 2 AND RL.EID = 4 AND RL.EID = V.EID
    > GROUP BY RL.EID, V.PlacesMax, V.PlacesMin, V.EventPlaces)
    >
    > tbl_tmp1
    >
    > WHERE EID = 4
    >
    > Query 2
    > ---------------
    >
    > SELECT EID, Status AS TheStatus, RLID, PlacesNo, FName, LName,
    Organisation,
    > RecievedDate, JobRole
    > FROM dbo.tbl_ep_Returns_List
    > WHERE RLID = 22
    >
    >

    Bob Barrows Guest

  4. #3

    Default Re: Joining these two queries

    Hi thanks for replying Bob you assumed right. I'm using Version 7.

    Using the below i got the following "Incorrect syntax near the keyword
    'ON'."


    I used the following

    SELECT * FROM

    (SELECT COUNT(DISTINCT RLID) AS NoBooked, SUM(PlacesNo) AS NoPlacesTaken,
    RL.EID, V.EventPlaces, CAST (V.EventPlaces-SUM(PlacesNo) AS Int) AS
    PlacesAvailable
    FROM tbl_ep_Returns_List RL, tbl_ep_Venue V
    WHERE RL.Status <= 2 AND RL.EID = 4 AND RL.EID = V.EID
    GROUP BY RL.EID, V.PlacesMax, V.PlacesMin, V.EventPlaces)

    q1

    INNER JOIN

    (SELECT EID, Status AS TheStatus, RLID, PlacesNo, FName, LName,
    Organisation, RecievedDate, JobRole
    FROM dbo.tbl_ep_Returns_List
    WHERE RLID = 22)

    ON q1.EID = q2.EID




    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:ur3XJzs2DHA.2556@TK2MSFTNGP10.phx.gbl...
    > Assuming this is SQL Server(what version, please?)
    > Select * FROM
    > (Query1) q1
    > INNER JOIN
    > (Query2) q2
    > ON q1.<joining column> = q2.<joining column>
    >
    > Bob Barrows
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From header
    is
    > my spam trap, so I don't check it very often. You will get a quicker
    > response by posting to the newsgroup.
    > "Robert J Egan" <rob_j_egan@hotmail.com> wrote in message
    > news:epRgTPs2DHA.2544@TK2MSFTNGP10.phx.gbl...
    > > Can anyone help me to join Query 1 to Query 2
    > >
    > > cheers
    > > rob
    > >
    > > Query 1
    > > -------------
    > >
    > > SELECT * FROM
    > >
    > > (SELECT COUNT(DISTINCT RLID) AS NoBooked, SUM(PlacesNo) AS
    NoPlacesTaken,
    > > RL.EID, V.EventPlaces, CAST (V.EventPlaces-SUM(PlacesNo) AS Int) AS
    > > PlacesAvailable
    > > FROM tbl_ep_Returns_List RL, tbl_ep_Venue V
    > > WHERE RL.Status <= 2 AND RL.EID = 4 AND RL.EID = V.EID
    > > GROUP BY RL.EID, V.PlacesMax, V.PlacesMin, V.EventPlaces)
    > >
    > > tbl_tmp1
    > >
    > > WHERE EID = 4
    > >
    > > Query 2
    > > ---------------
    > >
    > > SELECT EID, Status AS TheStatus, RLID, PlacesNo, FName, LName,
    > Organisation,
    > > RecievedDate, JobRole
    > > FROM dbo.tbl_ep_Returns_List
    > > WHERE RLID = 22
    > >
    > >
    >
    >

    Robert J Egan Guest

  5. #4

    Default Re: Joining these two queries

    Robert J Egan wrote:
    > Hi thanks for replying Bob you assumed right. I'm using Version 7.
    >
    > Using the below i got the following "Incorrect syntax near the keyword
    > 'ON'."
    >
    >
    > I used the following
    >
    > SELECT * FROM
    >
    > (SELECT COUNT(DISTINCT RLID) AS NoBooked, SUM(PlacesNo) AS
    > NoPlacesTaken, RL.EID, V.EventPlaces, CAST
    > (V.EventPlaces-SUM(PlacesNo) AS Int) AS PlacesAvailable
    > FROM tbl_ep_Returns_List RL, tbl_ep_Venue V
    > WHERE RL.Status <= 2 AND RL.EID = 4 AND RL.EID = V.EID
    > GROUP BY RL.EID, V.PlacesMax, V.PlacesMin, V.EventPlaces)
    >
    > q1
    >
    > INNER JOIN
    >
    > (SELECT EID, Status AS TheStatus, RLID, PlacesNo, FName, LName,
    > Organisation, RecievedDate, JobRole
    > FROM dbo.tbl_ep_Returns_List
    > WHERE RLID = 22)
    >
    > ON q1.EID = q2.EID
    >
    >
    You left out the q2 alias:

    WHERE RLID = 22) q2


    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  6. #5

    Default Re: Joining these two queries

    It works!

    Thanks Bob, you've been a great help for me.

    rob :)


    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:ew$2pX12DHA.1908@TK2MSFTNGP10.phx.gbl...
    > Robert J Egan wrote:
    > > Hi thanks for replying Bob you assumed right. I'm using Version 7.
    > >
    > > Using the below i got the following "Incorrect syntax near the keyword
    > > 'ON'."
    > >
    > >
    > > I used the following
    > >
    > > SELECT * FROM
    > >
    > > (SELECT COUNT(DISTINCT RLID) AS NoBooked, SUM(PlacesNo) AS
    > > NoPlacesTaken, RL.EID, V.EventPlaces, CAST
    > > (V.EventPlaces-SUM(PlacesNo) AS Int) AS PlacesAvailable
    > > FROM tbl_ep_Returns_List RL, tbl_ep_Venue V
    > > WHERE RL.Status <= 2 AND RL.EID = 4 AND RL.EID = V.EID
    > > GROUP BY RL.EID, V.PlacesMax, V.PlacesMin, V.EventPlaces)
    > >
    > > q1
    > >
    > > INNER JOIN
    > >
    > > (SELECT EID, Status AS TheStatus, RLID, PlacesNo, FName, LName,
    > > Organisation, RecievedDate, JobRole
    > > FROM dbo.tbl_ep_Returns_List
    > > WHERE RLID = 22)
    > >
    > > ON q1.EID = q2.EID
    > >
    > >
    > You left out the q2 alias:
    >
    > WHERE RLID = 22) q2
    >
    >
    > Bob Barrows
    >
    > --
    > Microsoft MVP - ASP/ASP.NET
    > Please reply to the newsgroup. This email account is my spam trap so I
    > don't check it very often. If you must reply off-line, then remove the
    > "NO SPAM"
    >
    >

    Robert J Egan Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139