Follow

mysql commands


CommandUseSyntax
CREATE DATABASECreate a new databaseCREATE DATABASE dbname;
CREATE TABLECreate a new tableCREATE TABLE tablename (column1 datatype, column2 datatype, ...);
ALTER TABLEModify an existing tableALTER TABLE tablename ADD column datatype;
DROP TABLEDelete a tableDROP TABLE tablename;
INSERT INTOInsert data into a tableINSERT INTO tablename (column1, column2, ...) VALUES (value1, value2, ...);
SELECTRetrieve data from a tableSELECT column1, column2, ... FROM tablename;
UPDATEUpdate data in a tableUPDATE tablename SET column1 = value1, column2 = value2 WHERE condition;
DELETEDelete data from a tableDELETE FROM tablename WHERE condition;
TRUNCATE TABLEDelete all data from a tableTRUNCATE TABLE tablename;
ALTER USERModify a user's accountALTER USER 'user'@'host' IDENTIFIED BY 'password';
CREATE USERCreate a new user accountCREATE USER 'user'@'host' IDENTIFIED BY 'password';
DROP USERDelete a user accountDROP USER 'user'@'host';
GRANTGrant privileges to a user accountGRANT privilege1, privilege2, ... ON databasename.tablename TO 'user'@'host';
REVOKERevoke privileges from a user accountREVOKE privilege1, privilege2, ... ON databasename.tablename FROM 'user'@'host';
SHOW DATABASESShow a list of databasesSHOW DATABASES;
SHOW TABLESShow a list of tables in a databaseSHOW TABLES FROM databasename;
DESCRIBEShow the structure of a tableDESCRIBE tablename;
USESelect a database to work withUSE databasename;
COUNTCount the number of rows in a tableSELECT COUNT(*) FROM tablename;
MAXFind the maximum value in a columnSELECT MAX(columnname) FROM tablename;
MINFind the minimum value in a columnSELECT MIN(columnname) FROM tablename;
AVGCalculate the average value of a columnSELECT AVG(columnname) FROM tablename;
SUMCalculate the sum of a columnSELECT SUM(columnname) FROM tablename;
GROUP BYGroup rows based on a columnSELECT columnname, COUNT(*) FROM tablename GROUP BY columnname;
ORDER BYSort rows based on a columnSELECT columnname1, columnname2, ... FROM tablename ORDER BY columnname ASC/DESC;
JOINCombine data from two or more tablesSELECT columnname1, columnname2, ... FROM tablename1 JOIN tablename2 ON tablename1.columnname = tablename2.columnname;
LEFT JOINCombine data from two tables, including all rows from the left tableSELECT columnname1, columnname2, ... FROM tablename1 LEFT JOIN tablename2 ON tablename1.columnname = tablename2.columnname;
RIGHT JOINCombine data from two tables, including all rows from the right table`SELECT columnname1, columnname2, ... FROM tablename1 RIGHT JOIN tablename2 ON tablename1.columnname = tablename2.column
SELECTRetrieve data from a databaseSELECT column1, column2 FROM table_name;
INSERTInsert new data into a databaseINSERT INTO table_name (column1, column2) VALUES (value1, value2);
UPDATEModify existing data in a databaseUPDATE table_name SET column1 = value1, column2 = value2 WHERE condition;
DELETEDelete data from a databaseDELETE FROM table_name WHERE condition;
CREATE DATABASECreate a new databaseCREATE DATABASE database_name;
CREATE TABLECreate a new tableCREATE TABLE table_name (column1 datatype, column2 datatype);
DROP DATABASEDelete a databaseDROP DATABASE database_name;
DROP TABLEDelete a tableDROP TABLE table_name;
ALTER TABLEModify an existing tableALTER TABLE table_name ADD column datatype;
SHOW DATABASESDisplay a list of all databasesSHOW DATABASES;
SHOW TABLESDisplay a list of all tables in a databaseSHOW TABLES;
DESCDisplay information about a tableDESC table_name;
LIKESearch for data that matches a specific patternSELECT * FROM table_name WHERE column LIKE 'pattern';
INSearch for data that matches a list of valuesSELECT * FROM table_name WHERE column IN (value1, value2);
BETWEENSearch for data that falls within a rangeSELECT * FROM table_name WHERE column BETWEEN value1 AND value2;
ORDER BYSort data in ascending or descending orderSELECT * FROM table_name ORDER BY column ASC/DESC;
GROUP BYGroup data by a specific columnSELECT column, COUNT(*) FROM table_name GROUP BY column;
HAVINGFilter data based on aggregate functionsSELECT column, COUNT() FROM table_name GROUP BY column HAVING COUNT() > value;
DISTINCTRetrieve unique values from a columnSELECT DISTINCT column FROM table_name;
COUNTCount the number of rows in a tableSELECT COUNT(*) FROM table_name;
SUMCalculate the sum of values in a columnSELECT SUM(column) FROM table_name;
AVGCalculate the average value of a columnSELECT AVG(column) FROM table_name;
MAXRetrieve the highest value in a columnSELECT MAX(column) FROM table_name;
MINRetrieve the lowest value in a columnSELECT MIN(column) FROM table_name;
JOINCombine data from multiple tablesSELECT * FROM table1 JOIN table2 ON table1.column = table2.column;
LEFT JOINCombine data from two tables, including all rows from the left tableSELECT * FROM table1 LEFT JOIN table2 ON table1.column = table2.column;
RIGHT JOINCombine data from two tables, including all rows from the right tableSELECT * FROM table1 RIGHT JOIN table2 ON table1.column = table2.column;
FULL OUTER JOINCombine data from two tables, including all rows from both tablesSELECT * FROM table1 FULL OUTER JOIN table2 ON table1.column = table2.column;
INNER JOINCombine data from two tables, including only matching rowsSELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column;
UNIONCombine the results of two or more SELECT statementsSELECT column1 FROM table1 UNION SELECT column2 FROM table2;
LIMITLimit the number of rows returned by a SELECT statementSELECT * FROM table_name LIMIT number;

No comments:

Post a Comment

Tell us how you like it.