Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To join 2 Queries??

Status
Not open for further replies.

zaq888

MIS
Jun 2, 2003
46
MY
This is the first one..

SELECT TUnit.[cs-username]
FROM TUnit LEFT JOIN [SELECT * FROM Tdata WHERE Tdata.date BETWEEN ? AND ?]. AS MyTempTbl ON TUnit.[cs-username] = MyTempTbl.[cs-username]
WHERE (((MyTempTbl.[cs-username]) Is Null))
ORDER BY Tunit.[cs-username];

N this is the second one :

SELECT Sum(TData.[time-taken]) AS [Total Of Minutes Login]
FROM TData;


I'm Keep Studying.... please show the way...
Not Good in English
 
Hi, its me again

The first query returns usernames where there is NO data for this username in TData - so there is nothing to sum by username. Can you clarify what you are trying to do with the second sql statement. It does not make logical sense to me to combine it with the first one.

 
what i mean is like this :
from the temp table that is range from ? to ? date, i also would like to sum the colum time-taken which is in the group table TData also... How can i do that sir???

I'm Keep Studying.... please show the way...
Not Good in English
 
To select the sum change the query to this

SELECT [cs-username], Sum(TData.[time-taken]) AS [Total Of Minutes Login]
FROM Tdata
GROUP BY [cs-username]
WHERE Tdata.date BETWEEN ? AND ?

By itself this gives meaningfull data - But as I said this will serve no purpose if joined with the first query as the rows you are extracting are those with NO rows in MyTemTbl.
If the WHERE (((MyTempTbl.[cs-username]) Is Null)) is true then [Total Of Minutes Login] will also be Null.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top