MYSQL NOTES
This is a note of MySQL datbase for future review
1. Basic Concept#
- DB: database, a container used to store data.
- DBMS: database management system, a system used to create or manamge database
- SQL: strucutred query language, a kind of way to communicate with database.
2. DQL (Data query language)#
1. Syntax#
select col_name
from table_name;
2. Character#
- col_name can be a single or muliple column, constant value, expression, function
- the result is a virtual table
3. Example#
- Query a single column
- select col_name from table_name;
- Query multiple columns
- select col_name1, col_name2 from table_name;
- Query all columns
- select * from table_name;
- Query constant value
- select * cons_val
- constant value with char and date must be quoted with single quote.
- Query function
- select function_name(parm_list)
- Query expression
- select 100/1234;
- alias
- as
- space
- distinct -> reduce duplication
- select distinct col_name from table_name;
- + // add operation
- select number1 + number2
- select character + number // trying to convert character to number. If succeed, continue calculation. If failed, regard character as 0.
- select null + any value // result would be always null
- concat function // do characters concatination
- select concat(char1, char2, char3, …);
- ifnull function // identify xxx is null or not null. if null, return 0 or return original value
- select ifnull(xxx, 0) from employees;
- isnull function // identify a col is null or nut, if null, return 1 or return 0