Code Monkey home page Code Monkey logo

basic-sql-commands's Introduction

Basic-SQL-Commands

// Basic SQL Commands

Create

CREATE TABLE `book` (`book_id` INT NOT NULL AUTO_INCREMENT , `book_name` VARCHAR(50) NOT NULL , `book_price` INT(5) NOT NULL , `book_writter` VARCHAR(50) NOT NULL , PRIMARY KEY (`book_id`))

Insert

INSERT INTO `book` (`book_id`, `book_name`, `book_price`, `book_writter`) VALUES ('101', 'Bangla', '100', 'Sakib'), (NULL, 'English', '150', 'Tahmeed'), (NULL, 'Arabic', '200', 'Tamim')

1 Select All

SELECT *
FROM orderlist

2 Select All (Distinct)

SELECT DISTINCT Invoice
FROM orderlist

3 Where

SELECT *
FROM orderlist
WHERE id = 25

4 And, OR, NOT

SELECT *
FROM orderlist
WHERE Id = 10 AND Invoice = 'abcxyz'
SELECT *
FROM orderlist
WHERE Id = 10 OR Invoice = 'abcxyz'
SELECT *
FROM orderlist
WHERE NOT RefTrx = 'AAE0M3JW8Q'

5 Order By

SELECT *
FROM orderlist
ORDER BY Id ASC
SELECT *
FROM orderlist
ORDER BY Id DESC

6 Insert Into

INSERT INTO orderlist (`Id`,`Invoice`,`RefTrx`)
VALUES (1000, 'testInvoiceId', 'testRefTrx');

7 Update

UPDATE orderlist
SET RefTrx = 'updatedRefId', Invoice = 4.1254
WHERE id = 5;

8 Delete

DELETE
FROM orderlist
WHERE Id = 7;

9 Avg, Min, Max, Count, Sum

SELECT AVG(Amount)
FROM paystation
WHERE Payment_Method = 'bKash';
SELECT MIN(Amount)
FROM paystation
WHERE Payment_Method = 'bKash';
SELECT MAX(Amount)
FROM paystation
WHERE Payment_Method = 'bKash';
SELECT SUM(Amount)
FROM paystation
WHERE Payment_Method = 'bKash';
SELECT COUNT(Amount)
FROM paystation
WHERE Payment_Method = 'bKash';

10 Like (Starts with 015)

SELECT *
FROM paystation
WHERE Customer_Mobile LIKE '015%';

11 Like (Contains 015)

SELECT *
FROM paystation
WHERE Customer_Mobile LIKE '%015%';

12 Like (Starts with 0 and has at least 2 characters)

SELECT *
FROM paystation
WHERE Customer_Mobile LIKE '0_';

13 In (Select where contains these values)

SELECT * 
FROM paystation
WHERE Payment_Method IN ('Nagad', 'Rocket');
SELECT * 
FROM paystation
WHERE Payment_Method IN ('Nagad', 'Rocket');

14 In (Select where contains values from another table)

SELECT * 
FROM paystation
WHERE Payment_Method IN (SELECT Payment_Method FROM anothertable);

15 Between

SELECT * 
FROM paystation
WHERE Amount BETWEEN 0 AND 505

16 Alias

SELECT Amount AS 'Temp table title'
FROM paystation
WHERE 1

17 Join

SELECT table1.id, table2.name
FROM table1
INNER JOIN table2 ON table1.id = taabl2.id
SELECT table1.id, table2.name
FROM table1
LEFT JOIN table2 ON table1.id = taabl2.id
SELECT table1.id, table2.name
FROM table1
RIGHT JOIN table2 ON table1.id = taabl2.id
SELECT table1.id, table2.name
FROM table1
CROSS JOIN table2 ON table1.id = taabl2.id

18 Union

SELECT id FROM table1
UNION
SELECT id FROM table2

19 Alter

ALTER TABLE paystation
ADD name varchar(255)
ALTER TABLE paystation
DROP COLUMN name;
ALTER TABLE paystation
MODIFY COLUMN Action varchar(255);

basic-sql-commands's People

Contributors

thetahmeed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.