Solved

Help combining these two queries?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

24 Experts available now in Live!

Get 1:1 Help Now