Subject | Re: select from 2 tables with certain values identical |
---|---|
Author | Svein Erling Tysvær |
Post date | 2005-06-06T15:05:22Z |
No Thomas, field names doesn't have to match - just the number of
fields and their definition.
SELECT A.Field1
FROM A
UNION
SELECT B.Field6
FROM B
will work, whereas
SELECT A.Field1, B.Field6
FROM A JOIN B ON A.Field2 = B.Field6
UNION
SELECT A.Field1
FROM A
will fail since the number of fields differ. The one thing you could
try is
...UNION SELECT Cast(A.Field1 As Varchar(40))...
(should be more important if you use constants, if both fields are
varchar(40) I don't understand if casting is necessary)
HTH,
Set
fields and their definition.
SELECT A.Field1
FROM A
UNION
SELECT B.Field6
FROM B
will work, whereas
SELECT A.Field1, B.Field6
FROM A JOIN B ON A.Field2 = B.Field6
UNION
SELECT A.Field1
FROM A
will fail since the number of fields differ. The one thing you could
try is
...UNION SELECT Cast(A.Field1 As Varchar(40))...
(should be more important if you use constants, if both fields are
varchar(40) I don't understand if casting is necessary)
HTH,
Set
--- In firebird-support@yahoogroups.com, Thomas Besand wrote:
> Hi Set and everybody,
>
> >You may concatenate the two above queries using UNION, but be aware
> >that the types then must match.
> >
> Is it true, that for a UNION not only types must match, but also
> fieldnames? In my particular case, fieldtypes and sizes do match
> (they're all varchar(40)), but IBOConsole burps with the UNION
> query with the following error
> <count of column list and variable list do not match>
> The names of the fields do of course *not* match.
>
> cu
> Thomas Besand
> Berlin, Germany (feels like autumn again)
>
> Svein Erling Tysvær schrieb:
>
> >2. Give me all records from A and B excluding those that were
> >returned by the above query;
> >
> >I'd prefer to split this into two separate questions:
> >
> >2a. All records from A that doesn't have a matching record in B
> >
> >select <something>
> >from a
> >where not exists(select * from b
> >where A.fld2=B.fld6 and A.fld3=B.fld7 and A.fld4=B.fld9)
> >
> >2b. All records from B that doesn't have a matching record in A
> >
> >select <something>
> >from b
> >where not exists(select * from a
> >where A.fld2=B.fld6 and A.fld3=B.fld7 and A.fld4=B.fld9)
> >
> >You may concatenate the two above queries using UNION, but be aware
> >that the types then must match.
> >
> >Is that enough to get you going?
> >Set
> >(chilly) Oslo, Norway
> >
> >>BTW: I don't need the records in one resultset.
> >>for one query I need :
> >>
> >>1. Give me all records from A and B where A.fld2=B.fld6 and
> >>A.fld3=B.fld7 and A.fld4=B.fld9;
> >>
> >>and for another one, depending on the user's choice:
> >>2. Give me all records from A and B excluding those that were
> >>returned by the above query;