SQL in MySQL
1. Firstly we have to start MySQL 5.5 Command line client then we need to enter password, created during installation.
![](https://i0.wp.com/lh3.googleusercontent.com/-6v2TxdEeYjg/YTnEIsf97mI/AAAAAAAAHlI/QeOdH7G_9XcpIyf1RKzqO8Lcu72SXOeUgCLcBGAsYHQ/w640-h272/image.png?w=1400&ssl=1)
After entering password, screen looks like below
![](https://i0.wp.com/lh3.googleusercontent.com/--m0_ePg6uA8/YTnE2AFmoMI/AAAAAAAAHlQ/0JKEgnpznbU7ewbxZlKOYZtpiI5a9ZkEgCLcBGAsYHQ/w640-h232/image.png?w=1400&ssl=1)
2. To create database: Creation of database is necessary, before creating any table. To create a database in sql, follow following syntax.Syntax: – create database ;For Example: – create database kr;
![](https://i0.wp.com/lh3.googleusercontent.com/-XEbOEE-CoMk/YTnFZhFyb8I/AAAAAAAAHlY/swW0hE9XKf47a3_-0ED2yKc9WWfM8jhOACLcBGAsYHQ/w640-h242/image.png?w=1400&ssl=1)
3. To Use database: To use a created database the use query is used in sql statement.Syntax: – use ;For Example: – use kr;
![](https://i0.wp.com/lh3.googleusercontent.com/-Axz22KxXLCM/YTnFlZphSxI/AAAAAAAAHlc/xntOHFtDNDUAct_zU-rE7aOnLulUUVaMgCLcBGAsYHQ/w640-h258/image.png?w=1400&ssl=1)
4. To show databases: The show database is used to show list of all the databases in the sql statement.Syntax: – show database;
![](https://i0.wp.com/lh3.googleusercontent.com/-VMiicGrUy7M/YTnFuehThjI/AAAAAAAAHlk/nhgG8jUCCLAVvTcc_f85eJBkGdrvx_jAgCLcBGAsYHQ/w640-h348/image.png?w=1400&ssl=1)
5. To create table: To create a table in sql database we have to give table name along with columns names and its attributes into the database, See the syntax and example below.Syntax: – create table table-name (properties);For Example: – create table kr (name varchar (30), rollno int (10), address varchar (30));
![](https://i0.wp.com/lh3.googleusercontent.com/-zrQoYHQueP0/YTnGESZ2WyI/AAAAAAAAHlw/suFAOnXFwAgR3zUSa9PDgrGdZoNu5i7ngCLcBGAsYHQ/w640-h517/image.png?w=1400&ssl=1)
6. To insert value: To insert value in a table we have to follow below syntax and see the example below. Syntax: – insert into (table name) (properties name) values ( values name);For Example: – insert into kr (name, rollno, address) values (ks, 23, burhanpur);
![](https://i0.wp.com/lh3.googleusercontent.com/-vhk6R_PdQhA/YTnGYyjJ_mI/AAAAAAAAHl4/EVA1j2MRoz4Zzbq1To4GgmxNX1aqrgyLQCLcBGAsYHQ/w640-h462/image.png?w=1400&ssl=1)
7. Show tables: Show tables query is used to show the list of tables in selected database in sql.Syntax: – show tables;
![](https://i0.wp.com/lh3.googleusercontent.com/-WGk-86yqF9M/YTnG2dyIojI/AAAAAAAAHmA/sSYoz0E8nRUBVOmsFIUrxDQ8gFgKeLAngCLcBGAsYHQ/w640-h290/image.png?w=1400&ssl=1)
8. Select query: select query is used to show the selected database tables.Syntax: – select * from (table name);
![](https://i0.wp.com/lh3.googleusercontent.com/-vLUlOXjNzEg/YTnHOc8Zd2I/AAAAAAAAHmI/pKsgqWDoG9Q1ijaI6_n6cOGJHqN-pn__ACLcBGAsYHQ/w640-h212/image.png?w=1400&ssl=1)
9. Update: update query is used to update in the selected table.
![](https://i0.wp.com/lh3.googleusercontent.com/-MzfNrFxrHo8/YTnHW8G87lI/AAAAAAAAHmM/ApiIGOtbhc85vMVZ9eNRNJUEvy_OZadmQCLcBGAsYHQ/w640-h452/image.png?w=1400&ssl=1)
10. Group by:
![](https://i0.wp.com/lh3.googleusercontent.com/--xvCGfcfQlk/YTnHeR31IiI/AAAAAAAAHmU/IyHWzGIwdTYvEQD0P22jHYllGf6oiyTQgCLcBGAsYHQ/w640-h316/image.png?w=1400&ssl=1)
11. Like query:
![](https://i0.wp.com/lh3.googleusercontent.com/-05bSCfOb4-g/YTnHqz8IpOI/AAAAAAAAHmc/FsMxxLq5IMILjekL2rEIlb54L9rfF180wCLcBGAsYHQ/w640-h280/image.png?w=1400&ssl=1)
12. Distinct query:
![](https://i0.wp.com/lh3.googleusercontent.com/-Fo8IJtgU3Wo/YTnHyA0R27I/AAAAAAAAHmk/8K1J3sWxUF45lBufKDYaJnWUU865lWhZgCLcBGAsYHQ/w640-h158/image.png?w=1400&ssl=1)
13.Drop query:
![](https://i0.wp.com/lh3.googleusercontent.com/-AzpDPN0p7g8/YTnH9eTOtOI/AAAAAAAAHms/rXUClEnhO3M50zzbhjzVv77SoMW1buUewCLcBGAsYHQ/w640-h68/image.png?w=1400&ssl=1)