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 ???

Recommended Answers

All 4 Replies

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?

yes, same items, just diffrent price

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.

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.