SELECT <column1 en column2> FROM <table>
SELECT <column1 gedeeld door column2> FROM <table>
| DBMS | Syntax |
|---|---|
| SQL Server, MS Access | + |
| DB2, Oracle, PostgreSQL, SQLite | || |
| MySQL, MariaDB | function: concat |
CONCAT is a function. Functions are covered in the next chapter.
SELECT <text1> + <text2> SELECT <text1> || <text2> SELECT CONCAT(text1, text2)
Select vend_name and vend_country from Vendors and combine them. Put parentheses around vend_country and sort the result
-- MySQL - MariaDB SELECT CONCAT(vend_name,' (',vend_country,')') FROM Vendors ORDER BY vend_name;
| CONCAT(vend_name, ' (',vend_country,')') |
| Bear Emporium (USA) |
| Bears R Us (USA) |
| Doll House Inc. (USA) |
| Fun and Games (England) |
| Furball Inc. (USA) |
| Jouets et ours (France) |
-- Oracle - DB2 - PostgreSQL - SQLite SELECT TRIM(vend_name) || ' (' || TRIM(vend_country) || ')' FROM Vendors ORDER BY vend_name;
-- SQL Server SELECT TRIM(vend_name) + ' (' + TRIM(vend_country) + ')' FROM Vendors ORDER BY vend_name;
SELECT <value1> + <value2> AS <NewColumnName> FROM <table>
Select vend_name and vend_country from Vendors and combine them into a column named 'VendTitle'. Put parentheses around vend_country and sort the result
-- Oracle SELECT TRIM(vend_name) || ' (' || TRIM(vend_country) || ')' AS VendTitle FROM Vendors ORDER BY vend_name;
-- MySQL SELECT CONCAT(vend_name, ' (', vend_country, ')') AS VendTitle FROM Vendors ORDER BY vend_name;
-- SQL Server SELECT TRIM(vend_name) + ' (' + TRIM(vend_country) + ')' AS VendTitle FROM Vendors ORDER BY vend_name;
| VendTitle |
| Bear Emporium (USA) |
| Bears R Us (USA) |
| Doll House Inc. (USA) |
| Fun and Games (England) |
| Furball Inc. (USA) |
| Jouets et ours (France) |
| Operator | Description |
|---|---|
| + | Addition |
| - | Subtraction |
| / | Division |
| * | Multiplication |
Use parentheses ( ) to specify the order of operations in a calculation
-- MySQl / SQL Server SELECT 8*2+4-10/2;
-- Oracle (19c & 21C) SELECT 8*2+4-10/2 FROM DUAL;
SELECT <column1> * <column2> AS <column3> FROM <table>;
Select the product ID, quantity and price from OrderItems. Add a column that multiplies quantity by price and name it 'TotaalPrijs'. Sort by TotaalPrijs.
-- Oracle / MySQL / SQL Server SELECT prod_id, quantity, item_price, quantity * item_price AS TotaalPrijs FROM OrderItems ORDER BY TotaalPrijs;
| prod_id | quantity | item_price | TotaalPrijs |
| RGAN01 | 5 | 4.99 | 24.95 |
| BNBG01 | 10 | 3.49 | 34.9 |
| BNBG02 | 10 | 3.49 | 34.9 |
| BNBG03 | 10 | 3.49 | 34.9 |
| BR03 | 5 | 11.99 | 59.95 |
| BR02 | 10 | 8.99 | 89.9 |
| BR01 | 20 | 5.99 | 119.8 |
| BR03 | 10 | 11.99 | 119.9 |
| RGAN01 | 50 | 4.49 | 224.5 |
| BNBG01 | 100 | 2.99 | 299 |
| BNBG02 | 100 | 2.99 | 299 |
| BNBG03 | 100 | 2.99 | 299 |
| BR01 | 100 | 5.49 | 549 |
| BR03 | 50 | 11.49 | 574.5 |
| BNBG01 | 250 | 2.49 | 622.5 |
| BNBG02 | 250 | 2.49 | 622.5 |
| BNBG03 | 250 | 2.49 | 622.5 |
| BR03 | 100 | 10.99 | 1099 |