A
A
Alexey Lebedev2016-05-12 22:21:57
SQL
Alexey Lebedev, 2016-05-12 22:21:57

How to get unique rows in SQL?

We have a table with the following fields:
id, - regular record id
uid, - user id
day, - day of entry
session - session number
This way I will know how many entries each user has made

SELECT day, uid, count(*) as count FROM table GROUP BY day, uid ORDER BY day ASC

But I need how many unique users there were.
This can be done if everything is added to temporary, and:
SELECT day, count(*) as count FROM temp_table GROUP BY day ORDER BY day ASC

The question is how it is done optimally. I don't like temporary.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanan Yuzb, 2016-05-12
@swanrnd

Usedistinct

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question