Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining Two SELECT QUERIES

Status
Not open for further replies.

anon47

Programmer
Nov 28, 2006
80
US
I am tring to join two queries. I know the UNION SELECT doesn't work for this and I am tring to figure out how to query two tables with different field values. The code below is as far as I have got any help would be great>

SELECT DISTINCTROW AS_Projects.ClientID, AS_Projects.CName, Sum(AS_Projects.GECharge) AS ClientPayment
FROM AS_Projects WHERE ((AS_Projects.GEPaid)=No) AND ((AS_Projects.ClientID) Is Not Null) UNION SELECT AS_Banking.Date FROM AS_Banking WHERE ((((AS_Banking.Date) < Date()+1))) GROUP BY AS_Projects.ClientID, AS_Projects.CName, AS_Banking.Date ;
 
You should show some sample data and desired result for this question.

Ignorance of certain subjects is a great part of wisdom
 
Thanks for the resonse guys. What I am needing is to know what queries other than UNION will work when joining two selects togather I can then ajust. Example: on the Union part of the code it will look up the record based on the ID and give the date of that record that is in the date field but sence the fields are different in the two tables it doesn't work with a union.
 
Thanks PHV I am reading the Artical now on the link you sent
 
a UNION and a JOIN are two completely different things. Hopefully from the article you understand how to use a JOIN.

A UNION is used to combine the results of two queries with the same number of fields in the SELECT clause.

Let's say for some reason you have two tables with identical structure: CurrentCustomers and ArchivedCustomers and someone asks for a list of all customers the company has ever had, that's when you would use a UNION:
Code:
SELECT * FROM CurrentCustomers
UNION
SELECT * FROM ArchivedCustomers

HTH



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top