This time, I am gonna write the small, new things which I learnt before but by the time forgot them. Following the course on MySQL I will be noting down the stuff. As you might have noticed it is in the gist
format, so the notes will not be much comprehensive, but they will be in such a form that you can refer back again. Like a cheat sheet!
SELECT database();
SHOW COLUMNS FROM table_name;
-- or
DESC table_name;
SHOW WARNINGS;
NOTE: This ↑ will only work immediately after the warning come out.
C.R.U.D.: Create, Read, Update, Delete.
-- INSTEAD of this boring old ↓
SELECT
CONCAT(fname, ' ', lname, ' ', age)
FROM ...
-- Use CONCAT_WS (With Seperator)
SELECT
CONCAT_WS(' ', fname, lname, age)
FROM ...
Really cool! (which is like ' '.join([...]))
SELECT SUBSTRING('Aayush Shah', -4)
Returns → 'Shah'
SELECT col_1, col_2, col_3
FROM table
ORDER BY 2;
-- ↑ is equivalent to ORDER BY col_2
SELECT *
FROM table
LIMIT 3, 5
Here LIMIT from_where, howmany_from_where
does the indexing for us. The index starts with 0.
Check this cool group by USE CASE out: This my own gist
SELECT
IF(condition, 'THEN THIS', 'IF NOT THIS') AS nickname
FROM table;
Simple and easy. Just a one liner.