MySQL Interview Questions

 

0. What is the difference between inner join, left join and right join?

 

Connection Type

INNER JOIN (inner join)

LEFT OUTER JOIN

RIGHT OUTER JOIN (right outer join)

FULL OUTER JOIN (full outer join)

There are two types of joins: inner joins and outer joins. Inner joins are equijoins, and outer joins are divided into left, right, and full outer joins. The words INNER and OUTER in the connection type can be omitted.

Inner joins, also known as natural joins, allow only matching rows from both tables to appear in the result set. The returned result set selects all matching data in the two tables, and discards the unmatched data. Since inner joins delete all rows from the result table that do not match other joined tables, inner joins may cause loss of information.

Inner joins only display records that meet the join conditions, and outer joins display records from the table in addition to the records that meet the conditions. For example, if a left outer join is used, records from the left table are also displayed.

 

1. How to round the average value of the field MARKET_PRICE in the database table PRODUCT to one decimal place?

 

SELECT ROUND(AVG(MARKET_PRICE),1) FROM PRODUCT;

 

SQL AVG function

Definition and Usage

The AVG function returns the average of a numeric column. NULL values ​​are not included in the calculation.

SQL AVG() syntax

SELECT AVG(column_name) FROM table_name

 

ROUND()

Functions The ROUND function is used to round a numeric field to the specified number of decimal places.

SQL ROUND() syntax

SELECT ROUND(column_name,decimals) FROM table_name

Parameter Description

column_name Required. Field to round.

decimals Required. Specifies the number of decimal places to return.

 

2. How to query the records from the nth row to the mth row?

 

SELECT * FROM TABLE1 LIMIT N-1,M-1;

 

3. What are the advantages and disadvantages of indexes?

 

Benefit: You can create indexes on tables to query data more quickly and efficiently. Indexes cannot be seen by users, they can only be used to speed up searches/queries.

Disadvantage: Updating a table with an index takes more time than updating a table without an index, because the index itself also needs to be updated.

Therefore, it is ideal to create indexes only on columns (and tables) that are frequently searched.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325176182&siteId=291194637