in reply to perl dbi select question

What you are trying to do in the first query is called a INNER JOIN, so the query would be something like:

select count(*) from tableA
INNER JOIN tableB ON (tableA.tableAkey = tableB.tableBkey)

Here's the skinny:   when you want to get information from two or more tables, you do this by joining them, which is based on fields in the two tables (e.g. “table1key, table2key”, for example ... use any existing field-name(s) you have). For each unique value occurring (for an INNER join) in both tables, every occurrence of that value in one table will be associated with every occurrence of that value in the other, a so-called Cartesian product.

Conceptually, the “rest” of the actions requested by the query are then applied against the join-result.

Replies are listed 'Best First'.
Re^2: perl dbi select question
by baxy77bax (Deacon) on May 12, 2008 at 13:09 UTC
    ok

    why do you prefere inner join over select, i mean i was talking to a lot of people over some issues concerning the sql and everybody preferred join two tables over "select * from...where..."

    is that better , faster, or just a different school.

    for example i could do it by writing

    select ... from TableA where y in (select ... from TableB)... or something like this

    thanx

Re^2: perl dbi select question
by pc88mxer (Vicar) on May 12, 2008 at 16:38 UTC
    To clarify, an INNER JOIN is equivalent to a SELECT from multiple tables with a WHERE clause, i.e. these are the same:
    select count(*) from tableA INNER JOIN tableB ON (tableA.tableAkey = tableB.tableBkey) select count(*) from tableA, tableB WHERE tableA.tableAkey = tableB.tableBkey