Search Postgresql Archives

SQL query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am running the Postgres(8.2.11) on Windows.

I have 2 tables, one with users and one with locations.

user_table
---------------
user_id      user_code      price           value
1               22222            45.23      -97.82
2               33333             42.67      -98.32
3               44444             35.56     -76.32

locations
--------------
id       code     price        value
1        22222   45.23     -97.82
2        33333   42.67      -98.32
3        44444   43.26     -98.65

I have a query that takes every user and looks into locations to see if the code, price and value match up. If they do then count it.

select count(*)
  from user_table u, locations l
 where u.user_code = l.code
    and u.price = l.price
    and u.value = l.value;

The answer to this should be 2, but when I run my query I get 4 (in fact more entries than user_table) which is incorrect. What am I doing incorrectly? I have been breaking my head over this for a while. Is there some other query to get the required results? Any help would be highly appreciated. I gave a simple example above, but the query runs over 2 tables with about a million entries in each. So I am unable to verify what is wrong, but I know the count is incorrect as I should not have more than what is in the user_table.

Thanks,
Michael


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux