Reputation: 141
I have this table:
I need to query the table and ask the following questions:
How many rows matching uri 'x' exist with unique IP addresses between 'y' and 'z' dates.
I was experimenting with COUNTs but I couldn't seem to get the result I needed...
Upvotes: 2
Views: 696
Reputation: 1472
The DISTINCT keyword enforces that only unique entries are returned in the query. As the above answer by ConroyP mentions you can nest DISTINCT within other functions in SQL. Note that this is has a different function from 'UNIQUE' which enforces uniqueness constraints in the Data Definition Language part of SQL. Some databases also allow you to substitute the keyword UNIQUE for DISTINCT in the query - but this doesn't seem to work everywhere.
Upvotes: 1
Reputation: 41906
Try using COUNT(DISTINCT())
Returns a count of the number of rows with different non-NULL expr values.
So your query would be something like
SELECT COUNT( DISTINCT( user_ip ) )
FROM table
WHERE timestamp BETWEEN Y and Z
Upvotes: 5