Skip to main content
Documents
Share
LinkedIn
Facebook
Twitter
Copy
ClausesStatementsKeywordsExpressionsFunctions

Expressions

MySQL expressions are combinations of values, operators, and functions that evaluate to a single value. They are used in conditions, calculations, and dynamic query construction.

Common Uses of MySQL Expressions

  1. Arithmetic Expressions: Perform calculations.
  2. String Expressions: Manipulate text.
  3. Logical Expressions: Create conditions.
  4. Date Expressions: Handle date operations.
  5. Comparison Expressions: Compare values.

Examples

  1. Arithmetic Expression
     
    SELECT price * quantity AS total FROM orders;

    Explanation: Calculates the total price for each order.

  2. String Expression
     
    SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM users;

    Explanation: Combines first_name and last_name into a full name.

  3. Logical Expression
     
    SELECT * FROM orders WHERE amount > 50 AND status = 'Paid';

    Explanation: Filters orders with amount greater than 50 and status Paid.

  4. Date Expression
     
    SELECT CURDATE() - INTERVAL 30 DAY AS last_month;

    Explanation: Calculates the date 30 days ago.

  5. Comparison Expression
     
    SELECT * FROM employees WHERE salary BETWEEN 3000 AND 5000;

    Explanation: Filters employees with salaries between 3000 and 5000.