Solved

Help combining these two queries?

Posted on 2004-04-07
3
160 Views
Last Modified: 2010-04-01
I have query 1 that pulls in all fields from one table.
Now I need to pull in 1 field from a second table, and incorporate it into query 1, so I can display that one field along with all the other fields from query 1, and output to the user.

The field unique to both tables is the DATESTAMP field.  If a DATESTAMP field from TABLE1 matches the DATESTAMP field in TABLE2, then I want to capture its TOTAL_TIME and include it in query 1, so I can output it along with all the other fields in TABLE1.

I have tested both queries, and they work fine.
How can I combine them into one query so I can output all the fields necessary?
Here are the two queries:

Query 1:
SELECT * FROM TABLE1 WHERE CURDATE like '"+CURDATE+"%' and NODENAME='"+NODENAME2+"' order by "+ORDER_BY+""

Query 2:
SELECT DATESTAMP,TOTAL_TIME
FROM TABLE1, TABLE2
WHERE TABLE1.TYPE='IMMED' AND TABLE1.CLOSED='CLOSED' AND TABLE1.DATESTAMP=TABLE2.DATESTAMP
GROUP BY TABLE1.DATESTAMP, TABLE2.TOTAL_TIME
0
Comment
Question by:g118481
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
copyPasteGhost earned 150 total points
ID: 10774207
you would have to do something like this..

select (each field from table1), Total_time from table1, table2, where CURDATE like '"+CURDATE+"%' and NODENAME='"+NODENAME2+"' and TABLE1.TYPE='IMMED' AND TABLE1.CLOSED='CLOSED' AND TABLE1.DATESTAMP=TABLE2.DATESTAMP GROUP BY TABLE1.DATESTAMP, TABLE2.TOTAL_TIME order by "+ORDER_BY+""


that should work
Ghost
0
 
LVL 1

Author Comment

by:g118481
ID: 10774845
No, I do not believe your suggestion is what I am looking for.
0
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 10774882
>>How can I combine them into one query so I can output all the fields necessary?

what are the fields...

you do this..

select (all the fields)
from (all the tables)
where (all your conditions)
group by (all your groups)
order by (the fields you want your query to be ordered by);

if that's not what you want then I don't understand your question.
Ghost
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A procedure for exporting installed hotfix details of remote computers using powershell
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now