Results 1 to 2 of 2

Thread: LEFT JOIN returning duplicate columns

  1. #1
    Join Date
    Oct 2018
    Posts
    1

    LEFT JOIN returning duplicate columns

    Hi guys,

    What I want is a table of IPs and the then the number of impressions and clicks for each IP. Impressions and clicks are stored in separate tables where each row corresponds to one impression/click. So, what I want is all the impressions from the impressions table and all the matching clicks from the click table, grouped by IP address.

    The problem is that this query is returning the same number for clicks and impressions... which isn't possible, there should be more impressions than clicks in most cases. I've tried like 5 versions of the same query.

    SELECT i.ip_address AS ip, count(c.a_id) AS clicks, count(i.a_id) AS impressions
    FROM impressions_table AS i
    LEFT JOIN click_table AS c
    ON i.ip_address = c.ip_address
    WHERE i.id = '123456789'
    AND c.id = '123456789'
    AND i.timestamp>='2018-08-14-00'
    AND c.timestamp>='2018-08-14-00'
    GROUP BY ip

    Is there anything that stands out as being obviously wrong in my above query?

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Can you post the table definition for both tables and sample data

Posting Permissions

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