0

I have two tables with column name price

I want to order by price from both columns

so if is in first table 100eur and in second is 200eur

I want to order results like this: 200, 100

SELECT
    a.price,
    b.price
    FROM table1 AS a
    INNER JOIN table2 AS b ON a.sku = b.sku
    ORDER BY ???
3
Contributors
4
Replies
12
Views
3 Years
Discussion Span
Last Post by urtrivedi
0

The way you have your query you will end up with two columns, a.price and b.price, per row so your second requirement of having table 2 values first then table 1 doesn't really fit.
Do you have two tables containing the same items but just a different price in each one?

0

How about having 2 price columns in the one table then? Replicating all that data to hold a different price in another table isn't a particularly good idea.

0

I agree with hericles.

But as temporary solution following should work

SELECT
    a.price,
    b.price
    FROM table1 AS a
    INNER JOIN table2 AS b ON a.sku = b.sku
    ORDER BY case when a.price>=b.price then a.price else b.price end desc
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.