Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / General DB Topics / January 2005

Tip: Looking for answers? Try searching our database.

Joining Tables - Quick Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sams@centric.net - 26 Jan 2005 15:39 GMT
OK, I just can't seem to get this. It should be super easy for most of
you to answer.

I have 2 tables that are similar in design. 1st is called
"Applications". The 2nd is called "ExtraApplications". They both
contain vehicle "Year", "Make", "Model" and "Engine" columns. I need to
pull the unique records from both tables simultaneously.

For example, I am currently pulling the "Year" from the Applications
table like this:

<cfquery name="GetYear" datasource="ds" username="un" password="pw">
SELECT DISTINCT Year
FROM applications
ORDER BY Year DESC
</cfquery>

Very simple. Now, how do I join the ExtraApplications table in that
same query to pull all unique records from both??

Thanks in advance!
andrewst@onetel.com - 26 Jan 2005 15:56 GMT
SELECT Year
FROM applications
UNION
SELECT Year
FROM extraapplications
ORDER BY Year DESC
Jarl Hermansson - 26 Jan 2005 16:03 GMT
sams@centric.net wrote in news:1106753968.884736.111010
@c13g2000cwb.googlegroups.com:

> OK, I just can't seem to get this. It should be super easy for most of
> you to answer.
[quoted text clipped - 15 lines]
> Very simple. Now, how do I join the ExtraApplications table in that
> same query to pull all unique records from both??

SELECT Year FROM Applications
UNION
SELECT Year FROM ExtraApplications
ORDER BY Year DESC

UNION adds one result set to another, then all duplicates are removed.

Note that YEAR is a reserved word in SQL. To avoid future problems,
consider another column name.

HTH,
Jarl
sams@centric.net - 26 Jan 2005 16:12 GMT
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.