Solved

Help combining these two queries?

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The world seems to conceive of a curious bubble separating IT from “the business.”  More so than just about any other pursuit in the commercial world, people think of IT as some kind of an island.
Read the original post on Monitis Blog. Believe it or not, the most important thing about the website of your business is not what’s on it but how fast it loads. Yes, that’s right!    As you can see on this infographic (an oldie but goodie!), …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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