Subject Re: [firebird-support] Re: Using unions
Author Helen Borrie
At 09:24 AM 4/02/2004 +0000, you wrote:
>--- In firebird-support@yahoogroups.com, Aage Johansen <aagjohan@o...>
>wrote:
> > On Tue, 3 Feb 2004 20:19:46 +0000 (UTC), rajsubramani wrote:
> >
> > > I'm using firebird 1.0.
> > >
> > > When I try to do
> > >
> > > select book_id, price, '' as condition
> > > from Book
> > > UNION
> > > select bk.book_id, price, condition
> > > from Stock sk, Book bk where
> > > bk.book_id = sk.book_id
> > >
> > > I keep getting
> > > SQL error code = -104
> > > Invalid command
> > > Data type unknown
> > >
> >
> >
> >
> > The type of the empty string ('') is different from "condition".
> >
> > 1. Cast the '' to the type of "condition"
> > 2. Use aliases always when doing joins
> > 3. Use explicit joins (don't do it in the WHERE clause)
>
>Thanks for the reply, Aage. However, pardon my ignorance, I don not
>know how to transalate your suggestions to sql.
>
>1. Since condition is Blob sub type 1, how will the type cast look
>like in the sql statement.

You can't typecast to a blob, so you need to use a UDF, such as String2Blob
(in fbudf).


>2. Will the UNION not work if aliases are not used in the joins?

Too many double negatives here. See example below.


>3. Again I do not understand this, some sql example will be useful.

Here's a suggestion:

select
b1.book_id,
b1.price,
string2blob('') as condition from Book b1
UNION
select
bk.book_id,
sk.price,
bk.condition
from Book bk
join Stock sk on bk.book_id = sk.book_id

/hb