MYSQL Interview Questions

There is given MYSQL interview questions and answers that have been asked in many companies. Let's see the list of top MYSQL interview questions.

What is the query for displaying the top 20 rows?

Select* From table_name Limit 0 -20;.

What is the use of mysql_real_escape_string() function?

mysql_real_escape_string() function mainly used to escapes special characters in a string for use in an SQL statement.

How to find duplicate email records in users table?

SELECT u1.first_name, u1.last_name, u1.email FROM users as u1 INNER JOIN ( SELECT email FROM users GROUP BY email HAVING count(id) > 1 ) u2 ON u1.email = u2.email;.

How to get the 2nd highest salary of an employee, if two employees may have the same salary?

select salary from employee group by salary order by salary limit 1,1.

How can we encrypt and decrypt a data presented in a table using MySQL?

You can use functions: AES_ENCRYPT() and AES_DECRYPT() like:

AES_ENCRYPT(str,key_str);
AES_DECRYPT(crypt_str,key_str);
.

How many ways we can we find the current date using MySQL?

We can find current date using MySQL in different ways, they are:

SELECT CURDATE();
SELECT CURRENT_DATE();
SELECT CURTIME();
SELECT CURRENT_TIME();

.

How can we find the number of rows in a result set using PHP?

Here is how you can find the number of rows in a result set in PHP:

$result=mysql_query($any_valid_sql,$database_link);
$num_rows=mysql_num_rows($result);
echo“$num_rows rows found”;
.

What are the other commands to know the structure of a table using MySQL commands except EXPLAIN command?

DESCRIBE table_name;
.

How many values can the SET function of MySQL take?

MySQL SET function can take zero or more values, but at the maximum it can take 64 values.

.

What is the difference between mysql_fetch_object and mysql_fetch_array?

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array

.