Using distinct
We will now discuss another kind of query: the distinct
query. Firstly, however, we need to introduce another very useful function for the DBA called the coalesce
function. The coalesce
function, given two or more parameters, returns the first value that is not NULL
.
For example, let’s use the coalesce
function for the test
value:
forumdb=> select coalesce(NULL,'test');
coalesce
----------
test
(1 row)
In the preceding query, the coalesce
function returns test
because the first argument is NULL
and the second argument is not NULL
.
Now, let’s insert a new category:
forumdb=> insert into categories (title) values ('New Category');
INSERT 0 1
And then let’s perform the following query:
forumdb=# \pset null (NULL)
Null display is "(NULL)".
forumdb=> select pk,title,description from categories;
pk | title | description
----+-----------------------...