MySQL -QUERING DATA

por

en

DDL: Data definition language

DML: Data manipulation language

DCL: Data control language

Designed for managing relational databases

MySQL is versatile and can run on various platforms, including UNIX, Linux, and Windows. You can install it on a server or even on a desktop. What’s more, MySQL is renowned for its reliability, scalability, and speed.

MySQL SELECT FROM statement

SELECT select_list / column
FROM table_name;

MySQL SELECT

MySQL has many built-in functions like string functionsdate functions, and math functions. You can use the SELECT statement to execute one of these functions.

SELECT CONCAT(‘John’,’ ‘,’Doe’);

SELECT NOW();

SELECT 1 + 1;

To change a column name of the result set, you can use a column alias:

SELECT expression AS column_alias;

To assign an alias to a column, you place the AS keyword after the expression followed by a column alias. The AS keyword is optional, so you can skip it like this:

SELECT expression column_alias;

To assign an alias to a column, you place the AS keyword after the expression followed by a column alias. The AS keyword is optional, so you can skip it like this:

SELECT CONCAT(‘Jane’,’ ‘,’Doe’) AS ‘Full name’;

MySQL ORDER BY clause

SELECT select_list
FROM table_name
ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], …;

SELECT orderNumber, orderlinenumber, quantityOrdered * priceEach AS subtotal
FROM orderdetails
ORDER BY quantityOrdered * priceEach DESC;

Introduction to MySQL WHERE clause

SELECT 
    lastName, 
    firstName, 
    jobTitle, 
    officeCode
FROM
    employees
WHERE
    jobtitle = 'Sales Rep' OR 
    officeCode = 1
ORDER BY 
    officeCode , 
    jobTitle;

MySQL DISTINCT clause

When querying data from a table, you may get duplicate rows. To remove these duplicate rows, you use the DISTINCT clause in the SELECT statement.

SELECT 
    DISTINCT lastname
FROM
    employees
ORDER BY 
    lastname;

When you specify a column that has NULL values in the DISTINCT clause, the DISTINCT clause will keep only one NULL value because it considers all NULL values are the same.

When you specify multiple columns in the DISTINCT clause, the DISTINCT clause will use the combination of values in these columns to determine the uniqueness of the row in the result set.

MySQL AND operator