user3684020
user3684020

Reputation: 103

In a select add fake rows when a columns have a specifc value

My query is:

SELECT email,price
FROM invoice
WHERE email='[email protected]'

I would like to add a fake row every time the field 'price' is equal to '99.00' for every result white the value price '21.00'

Example

Normal result

Email         Price
[email protected]   84,00
[email protected]   99,00
[email protected]   29,00
[email protected]   99,00

I would like result like this:

Email         Price
[email protected]   84,00
[email protected]   99,00
[email protected]   21,00
[email protected]   29,00
[email protected]   99,00
[email protected]   21,00

Upvotes: 0

Views: 574

Answers (1)

Andrews B Anthony
Andrews B Anthony

Reputation: 1381

use the below query to get the expected(modified in order) results If you use this query you won't get the results in the order

Email         Price
[email protected]   84,00
[email protected]   99,00
[email protected]   21,00
[email protected]   29,00
[email protected]   99,00
[email protected]   21,00

However you will get in the below order

Email         Price
[email protected]   84,00
[email protected]   99,00
[email protected]   29,00
[email protected]   99,00
[email protected]   21,00
[email protected]   21,00

The Query to use is

SELECT email,price
FROM invoice
WHERE email='[email protected]'
UNION ALL
SELECT email,21,00
FROM invoice
WHERE email='[email protected]'
AND Price=99,00

Upvotes: 1

Related Questions