Tutorial by Examples

CREATE TABLE stack( id INT, username VARCHAR(30) NOT NULL, password VARCHAR(30) NOT NULL ); INSERT INTO stack (`id`, `username`, `password`) VALUES (1, 'Foo', 'hiddenGem'); INSERT INTO stack (`id`, `username`, `password`) VALUES (2, 'Baa', 'verySecret'); Query SELECT id FROM ...
Query SELECT * FROM stack; Result +------+----------+----------+ | id | username | password | +------+----------+----------+ | 1 | admin | admin | | 2 | stack | stack | +------+----------+----------+ 2 rows in set (0.00 sec) You can select all columns from one table...
Query SELECT * FROM stack WHERE username = "admin" AND password = "admin"; Result +------+----------+----------+ | id | username | password | +------+----------+----------+ | 1 | admin | admin | +------+----------+----------+ 1 row in set (0.00 sec) Query...
CREATE TABLE stack ( id int AUTO_INCREMENT PRIMARY KEY, username VARCHAR(100) NOT NULL ); INSERT stack(username) VALUES ('admin'),('k admin'),('adm'),('a adm b'),('b XadmY c'), ('adm now'), ('not here'); "adm" anywhere: SELECT * FROM stack WHERE username LIKE "%adm%&q...
SQL aliases are used to temporarily rename a table or a column. They are generally used to improve readability. Query SELECT username AS val FROM stack; SELECT username val FROM stack; (Note: AS is syntactically optional.) Result +-------+ | val | +-------+ | admin | | stack | +----...
Query: SELECT * FROM Customers ORDER BY CustomerID LIMIT 3; Result: CustomerID CustomerName ContactName Address City PostalCode Country 1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Ge...
The DISTINCT clause after SELECT eliminates duplicate rows from the result set. CREATE TABLE `car` ( `car_id` INT UNSIGNED NOT NULL PRIMARY KEY, `name` VARCHAR(20), `price` DECIMAL(8,2) ); INSERT INTO CAR (`car_id`, `name`, `price`) VALUES (1, 'Audi A1', '20000'); INSERT INTO CA...
A _ character in a LIKE clause pattern matches a single character. Query SELECT username FROM users WHERE users LIKE 'admin_'; Result +----------+ | username | +----------+ | admin1 | | admin2 | | admin- | | adminA | +----------+
Query SELECT st.name, st.percentage, CASE WHEN st.percentage >= 35 THEN 'Pass' ELSE 'Fail' END AS `Remark` FROM student AS st ; Result +--------------------------------+ | name | percentage | Remark | +--------------------------------+ | Isha | 67 | Pas...
You can use BETWEEN clause to replace a combination of "greater than equal AND less than equal" conditions. Data +----+-----------+ | id | username | +----+-----------+ | 1 | admin | | 2 | root | | 3 | toor | | 4 | mysql | | 5 | thanks | | 6 | java ...
SELECT ... WHERE dt >= '2017-02-01' AND dt < '2017-02-01' + INTERVAL 1 MONTH Sure, this could be done with BETWEEN and inclusion of 23:59:59. But, the pattern has this benefits: You don't have pre-calculate the end date (which is often an exact length from the start) You...

Page 1 of 1