Subject Re: [firebird-support] Re: does firebird always go fastest way?
Author Martijn Tonies
Hello Martin,


>thanx, the links did make join clearer but now i'm wondering whether
>join is indeed the right tool to get my query right (maybe my table
>structure is just a bit too extravagant for a beginner; dunno); see,
>join as i understand is useful to fetch fields from various tables at
>a time and into the same result set, right?

OR columns from a single table constraint by other tables.

eg: select the employees that work in a department where
John (employee # 10) is the boss.

select e.* // all columns from Employee (E)
from employee e
join department d on e.worksatdepartment = d.departmentnr
where d.boss = 10

See? There's a WHERE constraint on table "D", but due
to the JOIN, this will automatically restrict the output from
table "E".

>now, actually, i don't want that..in my query i only want to fetch
>fields from one table (dicentries) only the selection criterion for
>which records to pick makes the query so long
>
>imagine three tables as follows(only search-relevant fields mentioned):
>
>dicentries.id (primary key)
>dskrptlink_dicentries.id_dicentry (foreign key on field above)
>dskrptlink_dicentries.id_dskrpt (foreign key on field below)
>dskrpts.id (primary key)
>dskrpts.asdskrpt (search-relevant string)
>
>as this makes clear, a record in dicentries can have various
>corresponding records in dskrpts
>now, the user of my app would enter one or more such search-relevant
>strings(e.g.: 'abc', 'def', and 'ghi') into the mask after which a
>query should be generated fetching all those records from dicentries
>which are linked VIA table dskrptlink_dicentries to all of the
>following three records in dskrpts:
>
>r1: dskrpts.asdskrpt = 'abc'
>r2: dskrpts.asdskrpt = 'def'
>r3: dskrpts.asdskrpt = 'ghi'
>
>would someone please show me how to formulate this particular example
>in a time-efficient query just to put me on the right track?

With my example, you should be able to do that ;-)

Martijn Tonies
Database Workbench - development tool for Firebird and more!
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com