 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
kie Guest
|
Posted: Wed Jan 14, 2004 6:52 am Post subject: sql join between two similar tables |
|
|
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
|
Posted: Wed Jan 14, 2004 7:20 am Post subject: Re: sql join between two similar tables |
|
|
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
|
Posted: Wed Jan 14, 2004 1:02 pm Post subject: Re: sql join between two similar tables |
|
|
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 |
|
 |
|
|
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
|
|