-1

how can I replace column 'price' from 'products' to new 'price' from 'product_variations' and order by this new 'price'. Thank you for yours answers.

SELECT products.*, product_variations.price as `price`
FROM products
LEFT JOIN product_variations ON product_variations.product = products.id
ORDER BY price
  • You can use temp table like in this answer http://stackoverflow.com/questions/729197/sql-exclude-a-column-using-select-except-columna-from-tablea – Piotr Cz Mar 25 '15 at 22:35
  • unclear and maybe possible duplicate of http://stackoverflow.com/questions/729197/sql-exclude-a-column-using-select-except-columna-from-tablea – void Mar 25 '15 at 22:39

1 Answers1

0

products.* means all fields of products. if you don't want products.price, so don't use products.*, instead of it write all fields of products except than price:

SELECT 
    products.id,products.field_name_2,
    --...write all fields you want except than price 
    products.field_name_n,
    product_variations.price as `price`
FROM products
LEFT JOIN product_variations ON product_variations.product = products.id
ORDER BY price
void
  • 7,760
  • 3
  • 25
  • 43
  • `products.*` means `all field`s of `products` so if you don't want all of then you should not use it – void Mar 25 '15 at 22:21
  • But I need all of them. (my example code is reduced I need more than price) – Matej Janeček Mar 25 '15 at 22:23
  • you don't know what do you want, if you need them all so whay you told: _how can I replace column 'price' from 'products' to new 'price' from 'product_variations'_ !!???? :( – void Mar 25 '15 at 22:26
  • you are bothering others here. if _order is not just by price_ so why you have `ORDER BY price`(only price) in your code. I hope your question will get closed. – void Mar 25 '15 at 22:34
  • This is irrelevant. I want just replace one column with data from other. – Matej Janeček Mar 25 '15 at 22:36