Subject FW: [firebird-support] Is this legal SQL?
Author Henrik Sitter
Hi, Helen and Svein Erling!

Table 1:
Name -> TABLEONE
Columns -> ARTNR, HISTORY

Table 2:
Name -> TABLETWO
Columns -> ARTNR, COLOR

if (exists (select 1 from TABLEONE
where ARTNR in (select ARTNR from TABLETWO
where COLOR = 'aValue')
and HISTORY > 0
)
) then
begin
.
.
.
end

I hope the formatting doesn't get all f up... I'll have a look at your
solution Svein Erling. Thx for taking the time.

Henrik


-----Original Message-----
From: Helen Borrie [mailto:helebor@...]
Sent: 26. januar 2004 09:58
To: firebird-support@yahoogroups.com
Subject: RE: [firebird-support] Is this legal SQL?

At 09:06 AM 26/01/2004 +0100, you wrote:
>Thx for your reply Helen!
>
>But I don't think the offered solution will do the trick... I'll
>elaborate a bit just in case you (or others) have a bit more time to
>spare (I probably should buy myself a sql book).
>
>Lets say I have:
>***select 1 from table1 where col1 = 'aValue' and col2 = 'bValue'
>Both col1 and col2 belong to table1.
>
>But then I decide that col1 can be any value in an array, and this
array
>is built from a subquery. Then I get:
>select 1 from table1 where col1 in < subquery > and col2 = 'bValue'
>
>It's this construct I'm wondering about. Both col1 and col2 still
belong
>to table1. The way I read your solution col2 (i.e. HISTORIE) belongs to
>the subquery table (TABLE).

I read it that way because you wrote it that way.
How about you rephrase the original requirement and make it clear which
fields belong to which tables? In other words, use simple fieldnames
like
col1, etc., and qualify them with their table names.

I'm constantly amazed at how confused people get about their SQL for no
more obvious reason than they will do ANYTHING to avoid a line-feed and
a
space-character! ;-\

/hb





Yahoo! Groups Links

To visit your group on the web, go to:
http://groups.yahoo.com/group/firebird-support/

To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com

Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/