Solved

Help combining these two queries?

Posted on 2004-04-07
3
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Gain an elementary understanding of Blockchain technology.
Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

726 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