Here are the rest of the questions along with their answers:
Data Types:
- List some common MySQL data types.
- Common MySQL data types include INT, VARCHAR, CHAR, TEXT, DATE, TIMESTAMP, FLOAT, DOUBLE, etc.
- Differentiate between CHAR and VARCHAR data types.
- CHAR stores fixed-length character strings, while VARCHAR stores variable-length character strings.
- What is the maximum length of a VARCHAR in MySQL?
- The maximum length of a VARCHAR in MySQL is 65,535 characters.
- Explain the purpose of the INT data type.
- INT is used to store integer values within a specified range.
- Define FLOAT and DOUBLE data types.
- FLOAT and DOUBLE are used to store floating-point numbers with single and double precision, respectively.
- 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.
- Explain the TIMESTAMP data type.
- TIMESTAMP is used to store date and time values in the format YYYY-MM-DD HH:MM:SS.
- Describe the TEXT data type.
- TEXT is used to store large blocks of text data, such as paragraphs or documents.
- 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:
- 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;
- 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;
- 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;
- 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%';
- 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.
- 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.
- 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;
- You can sort records in MySQL using the ORDER BY clause.
- 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.
- Explain the purpose of the DISTINCT keyword.
- The DISTINCT keyword is used to retrieve unique values from a column in a table.
- 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;
- Joins in MySQL are performed using the JOIN keyword, specifying the tables to be joined and the join condition.
- 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.