S
S
sinevil2016-04-01 02:23:14
MySQL
sinevil, 2016-04-01 02:23:14

How to change SQL query?

And so, there is a request:

SELECT address FROM servers WHERE top = 1 OR vip = 1 ORDER BY date_endtop DESC, date_endvip DESC

It returns and sorts addresses according to two criteria. But if the address falls under top = 1 and vip = 1, then there will be only one address in the list. And I would like the address to be duplicated.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2016-04-01
@saboteur_kiev

Use Union, something like this:
SELECT address FROM servers WHERE top = 1
UNION
SELECT address from servers where vip = 1
ORDER BY date_endtop DESC, date_endvip DESC

R
res2001, 2016-04-01
@res2001

It may be necessary to include the top and vip fields or their sum in the query result. What do you want to get as an output?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question