Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009

    Unanswered: Trouble with querying

    Hello, I am new to SQL. I am currently using PostGres, but i think querying is pretty much the same?

    I have the following tables:
    common, cds, and position

    cds inherits common

    common and cds are linked by 'id'.

    common has values start and stop.

    I want to find all the 'position.target_pos' that lie within a cds region (the start and stop are obtained from common).

    I have this query:

    SELECT count(*) FROM common, cds, position WHERE = AND position.target_pos > common.start AND position.target_pos < common.stop
    however, this is returning me the value of over 1,000 which is impossible if my query is correct because there are only 800 entried in the position table. Therefor, i'm pretty sure my query is wrong, but i'm not sure where!!

    Please help!

  2. #2
    Join Date
    Dec 2008
    At work...
    Play around with smaller tables and you'll learn how joins work.

    If you have two tables, one with 4 rows and one with 5 rows, the join will return 4 * 5 = 20 rows if you have no join condition.

    (BTW, maybe you need some more join condition on the positions table.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts