A
A
Alistair O2017-01-23 06:45:53
SQL
Alistair O, 2017-01-23 06:45:53

How to sort correctly in sql?

Good afternoon,
tell me how to formulate the query correctly, there is a table with columns: pc_name, ip, db_name, action,
I need to embed an if condition,
for example, if pc_name = 1, ip=2, db_name=3,
only then do not display them in the result.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Draconian, 2017-01-23
@box4

The easiest way is to find out with a case whether a particular row needs to be displayed in the query, and then select only those that do not fall into the condition. Something like this:

select * from (
    select 
        case 
            when (pc_name = 1 and ip=2 and db_name = 3) then 0
            else 1
        end sort,
        ...
    from table
) q
where sort = 1

D
Dmitry Dart, 2017-01-23
@gobananas

If I understand the question correctly then:
Or (if on the contrary, this data is not needed)
Or
Selection sort is ORDER BY `column`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question