Skip to content
Advertisement

Query that only selects unique data

I just can’t make a request that will count only unique records.
There is a table: bbs with columns:

to_id – to whom
from_id – from whom

JavaScript

You need, for example, this data:

JavaScript

That is, for example, we are 1.
And it should count not 5, as it currently thinks, but 3.
You need to select 2 columns, only unique ones.
How to do this?

Advertisement

Answer

I’m guessing that you mean something like the following.

JavaScript

That query will return 3, using the sample data in your question.
Refer to this db<>fiddle.

I’m also guessing that the question marks in the [SQL] query in your question are place holders for a particular ID and you use an example value of 1 (one) in your question. Hence the where clause in my [SQL] query, above.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement