BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sql join between two similar tables

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop)
View previous topic :: View next topic  
Author Message
kie
Guest





PostPosted: Wed Jan 14, 2004 6:52 am    Post subject: sql join between two similar tables Reply with quote



I have two tables. Both tables are exactly the same except
one table contains data that is only 3 months old and the other
table contains data that is 3 to 48 months old. I want to search
both tables for specific records. The following is wrong as it
returns "millions" of records in the result set.
select field1, field2 from table1, table2 where field1 like %345

Can someone please help how to do the join properly from two
identical tables?

Thanks


Back to top
Ignacio Vazquez
Guest





PostPosted: Wed Jan 14, 2004 7:20 am    Post subject: Re: sql join between two similar tables Reply with quote



kie wrote:

Quote:
Can someone please help how to do the join properly from two
identical tables?

SELECT <fieldlist>
FROM <table1>
WHERE <conditionset>
UNION ALL
SELECT <fieldlist>
FROM <table2>
WHERE <conditionlist>

Note that this won't work with aggregate functions, and Delphi will
have problems with parameter names duplicated in both conditionsets,
but otherwise you should be golden.

--
Cheers,
Ignacio

Back to top
Bill Todd (TeamB)
Guest





PostPosted: Wed Jan 14, 2004 1:02 pm    Post subject: Re: sql join between two similar tables Reply with quote



On Wed, 14 Jan 2004 19:52:32 +1300, "kie" <kieakl (AT) ihug (DOT) co.nz> wrote:

Quote:
select field1, field2 from table1, table2 where field1 like %345

select field1, field2 from table1 where field1 like %345
UNION ALL
select field1, field2 from table2 where field1 like %345

Your query returns every possible combination of records between the
two tables.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.