Solved

Help combining these two queries?

Posted on 2004-04-07
3
162 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
library class in java 1 92
How to group array of objects ? 5 65
reflection example 3 102
login form jsp example 2 26
The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
As a business owner, there are many things that keep you up at night. Profit margins, employee retention, human resource protocols, whether your product or service will remain competitive. When you own or manage a technology company that operates la…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 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