Skip to content

Commit b1aef2a

Browse files
authored
Update README.md
1 parent 713e108 commit b1aef2a

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@ etc.
2020
I assume we're already familier with sql queries. So here some common querys to check out at a glance to rememorize again quickly.
2121

2222
### **_Insert:_**
23-
```
23+
```mysql
2424
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN) VALUES (value1, value2, value3,...valueN);
2525
```
2626
Now if we insert value in the same order as the columns in the table then we can use the following query insted of above one.
27-
```
27+
```mysql
2828
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
2929
```
3030

3131
### **_Select:_**
32-
```
32+
```mysql
3333
SELECT * FROM table_name;
3434
```
35-
```
35+
```mysql
3636
SELECT column1, column2, columnN FROM table_name;
3737
```
38-
```
38+
```mysql
3939
SELECT column1, column2, columnN FROM table_name WHERE [condition];
4040
```
4141
Example :<br> SELECT ID, NAME, SALARY FROM CUSTOMER WHERE SALARY > 20000;
42-
```
42+
```mysql
4343
SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]...AND [conditionN];
4444
```
4545
Example :<br> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000 AND age < 25;
46-
```
46+
```mysql
4747
SELECT column1, column2, columnN FROM table_name WHERE [condition1] OR [condition2]...OR [conditionN]
4848
```
4949
Example :<br> SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000 OR age < 25;
5050

5151
### **_Update:_**
52-
```
52+
```mysql
5353
UPDATE table_name SET column1 = value1, column2 = value2. .., columnN = valueN WHERE [condition];
5454
```
5555
Example :<br>
@@ -59,7 +59,7 @@ Example :<br>
5959
UPDATE CUSTOMERS SET ADDRESS = 'Pune', SALARY = 1000.00;
6060

6161
### **_Delete:_**
62-
```
62+
```mysql
6363
DELETE FROM table_name WHERE [condition];
6464
```
6565
Example :<br>
@@ -69,7 +69,7 @@ Example :<br>
6969
DELETE FROM CUSTOMERS WHERE ID = 6;
7070

7171
### **_Like:_**
72-
```
72+
```mysql
7373
SELECT FROM table_name
7474
WHERE column LIKE 'XXXX%'
7575

@@ -98,10 +98,10 @@ SELECT * FROM CUSTOMERS WHERE SALARY LIKE '200%'
9898

9999
### **_Limit:_**
100100

101-
```
101+
```mysql
102102
SELECT column_name(s) FROM table_name WHERE condition LIMIT number;
103103
```
104-
```
104+
```mysql
105105
SELECT * FROM Customers WHERE Country='Germany' LIMIT 3;
106106
```
107107
MySQL provides a LIMIT clause that is used to specify the number of records to return.
@@ -131,7 +131,7 @@ Notice that the numbers are reversed when you use a comma.
131131
### **_Order By :_**
132132

133133
This is used to sort the data in ascending or descending order, based on one or more columns.
134-
```
134+
```mysql
135135
SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2, .. columnN] [ASC | DESC];
136136
```
137137
Example :<br>
@@ -147,7 +147,7 @@ Note:This would sort the result in the descending order by NAME.
147147
### **_Group By :_**
148148

149149
This clause is used to group rows that have the same values.
150-
```
150+
```mysql
151151
SELECT column1, column2 FROM table_name WHERE [ conditions ] GROUP BY column1, column2 ORDER BY column1, column2
152152
```
153153
Example :<br>
@@ -156,7 +156,7 @@ SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME;
156156
For more [w3school](https://www.w3schools.com/sql/sql_groupby.asp) [tutorialpoint](https://www.tutorialspoint.com/sql/sql-group-by.htm)
157157

158158
### **_Join :_**
159-
```
159+
```mysql
160160
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
161161
```
162162
For details [w3school](https://www.w3schools.com/sql/sql_join.asp)
@@ -165,28 +165,28 @@ For details [w3school](https://www.w3schools.com/sql/sql_join.asp)
165165

166166
This used to combine the result-set of two or more SELECT statements.
167167

168-
```
168+
```mysql
169169
SELECT column_name(s) FROM table1 UNION SELECT column_name(s) FROM table2;
170170
```
171-
```
171+
```mysql
172172
SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2;
173173
```
174174

175175
---
176176
>**_Create database:_**
177-
```
177+
```mysql
178178
CREATE DATABASE DatabaseName;
179179
```
180180
>**_Delete database:_**
181-
```
181+
```mysql
182182
DROP DATABASE DatabaseName;
183183
```
184184
>**_Select database:_**
185-
```
185+
```mysql
186186
USE DatabaseName;
187187
```
188188
>**_Create table:_**
189-
```
189+
```mysql
190190
CREATE TABLE table_name(
191191
column1 datatype,
192192
column2 datatype,
@@ -197,25 +197,25 @@ CREATE TABLE table_name(
197197
);
198198
```
199199
>**_Delete table:_**
200-
```
200+
```mysql
201201
DROP TABLE table_name;
202202
```
203203
>**_Rename column:_**
204-
```
204+
```mysql
205205
ALTER TABLE tableName CHANGE `oldcolname` `newcolname` datatype(length);
206206
```
207207
>**_TRUNCATE:_**
208208
209209
By using the TRUNCATE TABLE statement, you delete all data from the table permanently and reset the auto-increment value to zero.
210-
```
210+
```mysql
211211
TRUNCATE TABLE table_name;
212212
```
213213
>**_Reset auto increment value using ALTER TABLE statement:_**
214-
```
214+
```mysql
215215
ALTER TABLE table_name AUTO_INCREMENT = value;
216216
```
217217
>**_Left join:_**
218-
```
218+
```mysql
219219
SELECT a.id, a.name, a.genericname, b.category, c.name AS manufacturer, a.shelf, a.price, a.manufacturerprice, a.strength, d.unit
220220
FROM medicine AS a
221221
LEFT JOIN medicine_category AS b ON a.category = b.id
@@ -229,6 +229,6 @@ echo "There was $d days in October 2005";
229229
```
230230

231231
### Find product from date range
232-
```php
233-
SELECT SUM(`payable`) as pr FROM `purchase` WHERE `store` = '1' and `date` between '2022-07-01' and '2022-07-31';
232+
```mysql
233+
SELECT SUM(`payable`) AS pr FROM `purchase` WHERE `store` = '1' AND `date` BETWEEN '2022-07-01' AND '2022-07-31';
234234
```

0 commit comments

Comments
 (0)