MySQL: Derived Tables
February 6th, 2009 by Elchie
If you have a table with columns like this:
- Manufacturer
- Model
- Price
Now you want to search by a concatenated string of manufacturer and model you can not do it like this:
select concat(manufacturer+’ ‘+model) as name, price from table where name = ‘Manu1 Testmodel’
You have to concat the columns within the where-area again. But MySQL (and MS-SQL also) supports derived tables, you can use a select as a “table” within the from and filter by the resulted columns, so the solution is:
select * from (select concat(manufacturer+’ ‘+model) as name, price from table) as tbl where name = ‘Manu1 Testmodel’
Just one important thing: Each derived table has to get an own alias.
Posted in Uncategorized