1.

MySQL DML(Data Manipulation Language) Commands

Answer»
COMMANDMEANINGSYNTAX
select *Displays all rows in a table. >SELECT * FROM TABLENAME
select * (multiple tables)Displays all the rows of the cartesian product of the two tables >SELECT * FROM TABLENAME1,TABLENAME2;
select columnsSelect particular columns from table(s) >SELECT COLUMN1,COLUMN2 FROM TABLENAME;
select with conditionDisplays rows based on a particular condition > SELECT * FROM TABLENAME WHERE CONDITION
select with multiple conditions(AND)Displays rows only when both the conditions are satisfied. > SELECT * FROM TABLENAME WHERE CONDITION1 AND CONDITION2.
select with multiple conditions(OR)Displays rows only when either of the conditions are satisfied. > SELECT * FROM TABLENAME WHERE CONDITION1 OR CONDITION2.
select with condition(NOT)Displays rows based on negation of a particular condition. >SELECT * FROM TABLENAME WHERE NOT CONDITION.
select with group byDisplays rows that have same values into summary rows > SELECT .. FROM .. WHERE… GROUP BY COLUMN3;
select with havingUsed instead of where for aggregate functions. >SELECT COUNT(COLUMN1) FROM TABLENAME ORDER BY COLUMN2 HAVING COUNT(COLUMN1)>3;
select distinctDisplay all unique rows discarding duplicate ones. >SELECT DISTINCT (COLUMN1) FROM TABLENAME;
order byUsed to sort results in ascending order or descending order > SELECT … FROM TABLENAME ORDER BY COLUMN1 ASC|DESC;
column aliasChanges the output of the name of the column. > SELECT COLUMN1 AS NEWNAME FROM TABLENAME;
likeUsed to search for a specific pattern. > SELECT COLUMN1 FROM TABLENAME WHERE COLUMN1 LIKE ‘%PATTERN%’;
insert recordAdds a new row to an existing table. > INSERT INTO TABLENAME (COLUMN1,COLUMN2…) VALUES (VALUE1,VALUE2…);
insert record(multiple)Adds multiple records into an existing table. > INSERT INTO TABLENAME (COLUMN1,COLUMN2…) VALUES (VALUE1A,VALUE2A…),(VALUE1B,VALUE2B,...);
deleteDeletes all records in a table. > DELETE FROM TABLENAME;
delete with whereDeletes specific records >DELETE FROM TABLENAME WHERE CONDITION;
betweenSelects values in a given range >SELECT * FROM TABLENAME WHERE AGE BETWEEN 25 AND 30.
inUsed instead of multiple OR operators. > SELECT * FROM TABLENAME WHERE COLUMN2 IN (V1,V2…);
existsTests for existence of a certain record. Returns a boolean value. > SELECT * FROM TABLE NAME WHERE EXIST (SUB QUERY);
update tableModifies data in existing tables. > UPDATE TABLENAME SET COLUMNNAME=VALUE WHERE CONDITION;
inner joinSelects records that have the same values in two same or distinct tables. > SELECT COLUMN(S) FROM TABLENAME1 INNER JOIN TABLENAME2 ON TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME;
left joinSelects all the records from the left table and matching records from the right table. >SELECT COLUMN(S) FROM TABLENAME1 LEFT JOIN TABLENAME2 ON TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME;
right joinSelects all the records from the right table and matching records from the left table. >SELECT COLUMN(S) FROM TABLENAME1 RIGHT JOIN TABLENAME2 ON TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME;
cross joinSelects rows from cartesian product of both the tables. >SELECT COLUMN(S) FROM TABLE1 CROSS JOIN TABLE2;
full outer join Selects all records with a match on table1 or table2. >SELECT COLUMN(S) FROM TABLENAME1 FULL OUTER JOIN TABLENAME2 ON TABLENAME1.COLUMNAME=TABLENAME2.COLUMNAME WHERE CONDITION;
unionCombines the result of two select statements. >SELECT * FROM TABLENAME1
UNION SELECT * FROM TABLENAME2
union allSimilar to Union but allows duplicate values >SELECT * FROM TABLENAME1
UNION ALL SELECT * FROM TABLENAME2
concat() Combines two or more columns together. >SELECT CONCAT(COLUMN1, " ", POSTALCODE, " ", COLUMN2) AS NEWCOL
FROM TABLENAME;



Discussion

No Comment Found