A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

Types of the JOINs in SQL

  • (INNER) JOIN: Returns records that have matching values in both tables
  • LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table
  • RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table
  • FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

Example

SELECT
  Orders.OrderID,
  Customers.CustomerName,
  Orders.OrderDate
FROM
  Orders
  INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
EXPLAIN table_name;

ALTER TABLE
  table_name
ADD
  column_name varchar(255);
ALTER TABLE
    user_management
ADD
    COLUMN flag INT DEFAULT 0,
ADD
    COLUMN id_created_by int(11);

Insert into table

INSERT INTO
table_name (title, type)
VALUES
('Test', 'Type 1');

 

INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas.

Example

INSERT INTO tbl_name
    (a,b,c)
VALUES
    (1,2,3),
    (4,5,6),
    (7,8,9);

Leave A Comment