Hello Friends, earlier I taught you how to create database end tables. If you haven’t, then you must have clicked here.
Friends, today we will tell about database queries. Which will work everywhere, you will be used in every project. The most out of these is insert, update, select and delete. These four things are very much in every project, irrespective of the type of database and database provider.
I am asking you to write an example with the name of each type of query, you can copy it and use it anywhere to insert and insert data from the database.
insert query
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
update query
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Select query
//select by column name SELECT column1, column2, ... FROM table_name; //or select all SELECT * FROM table_name; //or where condition SELECT column1, column2, ... FROM table_name WHERE condition; //or distinct SELECT DISTINCT Country FROM Customers; // or and condition SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condition3 ...; // or order by SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;
Delete query
DELETE FROM table_name WHERE condition;
SQL MIN MAX query
SELECT MIN(column_name) FROM table_name WHERE condition; SELECT MAX(column_name) FROM table_name WHERE condition;
min () The function returns the smallest value of the selected column.
max () The function returns the largest value for the selected column.
count average sum query
SELECT COUNT(column_name) FROM table_name WHERE condition; SELECT AVG(column_name) FROM table_name WHERE condition; SELECT SUM(column_name) FROM table_name WHERE condition;
chount () The function returns the number of rows matching the specified criteria.
avg () The function returns the average value of a numeric column.
sum () The function returns the sum of a numeric column
like query (This query is for the search function)
SELECT column1, column2, ... FROM table_name WHERE columnN LIKE pattern;
The type operator is used to search for a pattern specified in a column in the where clause.
Two wildcards are often used in combination with the written operator.
The% – percent sign represents zero, one or several characters.
_ – The underscore represents a single character.
join tables query
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;
join table ye bhi bade kam ki chiz hai ye do table ke bich connection banata hai.
dhyaan den ki “ordar” taalika mein “chustomairid” kolam “chustomairid” ko “graahak” taalika mein sandarbhit karata hai. oopar do taalikaon ke beech ka sambandh “chustomairid” kolam hai.
phir, ham nimnalikhit sql stetament (jisamen ek innair join hota hai) bana sakate hain, jo un rikords ka chayan karata hai jinamen donon tebalon mein maiching vailyooj hain
dosto hope aapko samaj me aa hi gaya or nahi aaya to ham apane courses me use karenge na example ke sath tabhi ache se samaj me aajayega. don’t worry.
happy coding.