Top 50 Fresher MYSQL Interview questions – Part 2

MYSQL Interview questions

Here are the rest of the questions along with their answers:

Data Types:

  1. List some common MySQL data types.
    • Common MySQL data types include INT, VARCHAR, CHAR, TEXT, DATE, TIMESTAMP, FLOAT, DOUBLE, etc.
  2. Differentiate between CHAR and VARCHAR data types.
    • CHAR stores fixed-length character strings, while VARCHAR stores variable-length character strings.
  3. What is the maximum length of a VARCHAR in MySQL?
    • The maximum length of a VARCHAR in MySQL is 65,535 characters.
  4. Explain the purpose of the INT data type.
    • INT is used to store integer values within a specified range.
  5. Define FLOAT and DOUBLE data types.
    • FLOAT and DOUBLE are used to store floating-point numbers with single and double precision, respectively.
  6. What is the purpose of the DATE data type?
    • The DATE data type is used to store date values in the format YYYY-MM-DD.
  7. Explain the TIMESTAMP data type.
    • TIMESTAMP is used to store date and time values in the format YYYY-MM-DD HH:MM:SS.
  8. Describe the TEXT data type.
    • TEXT is used to store large blocks of text data, such as paragraphs or documents.
  9. What is the BLOB data type used for?
    • BLOB (Binary Large Object) is used to store large binary data, such as images, videos, or files.

Queries:

  1. How do you select all records from a table?
    • To select all records from a table, you can use the following query:
    SELECT * FROM table_name;
  2. What is the syntax for selecting specific columns from a table?
    • To select specific columns from a table, you can use the following query:
    SELECT column1, column2 FROM table_name;
  3. How do you filter records using the WHERE clause?
    • You can filter records using the WHERE clause in the following way:
    SELECT * FROM table_name WHERE condition;
  4. Explain the LIKE operator.
    • The LIKE operator is used to search for a specified pattern in a column. It is often used with wildcard characters (% and _) to match patterns.
      Example:
    SELECT * FROM table_name WHERE column_name LIKE 'pattern%';
  5. What is the difference between WHERE and HAVING clauses?
    • The WHERE clause is used to filter rows before any groupings are applied, while the HAVING clause is used to filter rows after groupings have been applied in aggregate queries.
  6. How do you sort records in MySQL?
    • You can sort records in MySQL using the ORDER BY clause.
      Example:
    SELECT * FROM table_name ORDER BY column_name ASC/DESC;
  7. Define the GROUP BY clause.
    • The GROUP BY clause is used to group rows that have the same values into summary rows, typically used with aggregate functions like COUNT, SUM, AVG, etc.
  8. Explain the purpose of the DISTINCT keyword.
    • The DISTINCT keyword is used to retrieve unique values from a column in a table.
  9. How do you perform joins in MySQL?
    • Joins in MySQL are performed using the JOIN keyword, specifying the tables to be joined and the join condition.
      Example:
    SELECT * FROM table1 JOIN table2 ON table1.column_name = table2.column_name;
  10. Differentiate between INNER JOIN and OUTER JOIN.
    • INNER JOIN returns only the rows that have matching values in both tables, while OUTER JOIN returns all rows from both tables, with NULL values for unmatched rows.