How to search second maximum(second highest) salary value(integer)from table employee (field salary)in the manner so that mysql gets less load?

How to search second maximum(second highest) salary value(integer)from table employee (field salary)in the manner so that mysql gets less load?

By below query we will get second maximum(second highest) salary value(integer)from table employee (field salary)in the manner so that mysql gets less load? SELECT DISTINCT(salary) FROM employee order by salary desc limit 1 , 1 ; (This way we will able to find out 3rd highest , 4th highest salary so on just need to change limit condtion like LIMIT 2,1 for 3rd highest and LIMIT 3,1 for 4th some one may finding this way useing below query that taken…

Read More Read More

How to dump a table from a database

How to dump a table from a database

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql To dump a table from a MySQL database, you can use the mysqldump command-line tool. Here’s the basic syntax: bash mysqldump -u [username] -p [password] [database_name] [table_name] > [output_file.sql] Replace [username] with your MySQL username, [password] with your MySQL password, [database_name] with the name of the database containing the table you want to dump, [table_name] with the name of the table you want to dump, and [output_file.sql] with the…

Read More Read More

How to Delete a column and Add a new column to database

How to Delete a column and Add a new column to database

mysql> alter table [table name] drop column [column name]; mysql> alter table [table name] add column [new column name] varchar (20); To delete a column in MySQL, you would use the ALTER TABLE statement followed by the DROP COLUMN keyword. Here’s the syntax: sql ALTER TABLE table_name DROP COLUMN column_name; Replace table_name with the name of your table and column_name with the name of the column you want to delete. To add a new column, you would also use the…

Read More Read More

How to Join tables on common columns

How to Join tables on common columns

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id In MySQL, you can join tables on common columns using the JOIN clause in a SELECT statement. The common columns are specified in the ON clause. There are different types of joins, including INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN. Here’s a basic example using INNER JOIN: sql SELECT * FROM table1 INNER JOIN table2 ON table1.common_column…

Read More Read More

How you will Show all records not containing the name “sonia” AND the phone number ‘9876543210’ order by the phone_number field

How you will Show all records not containing the name “sonia” AND the phone number ‘9876543210’ order by the phone_number field

mysql> SELECT * FROM tablename WHERE name != “sonia” AND phone_number = ‘9876543210’ order by phone_number; To retrieve all records not containing the name “sonia” and the phone number ‘9876543210’ from a MySQL table, and order the results by the phone_number field, you can use the following SQL query: sql SELECT * FROM your_table_name WHERE name != ‘sonia’ AND phone_number != ‘9876543210’ ORDER BY phone_number; Replace your_table_name with the actual name of your table. This query selects all columns (*)…

Read More Read More

How to returns the columns and column information pertaining to the designated table

How to returns the columns and column information pertaining to the designated table

mysql> show columns from tablename; In MySQL, you can use the DESCRIBE statement or the SHOW COLUMNS statement to retrieve information about the columns of a table. Both commands provide details about the structure of a table. DESCRIBE statement: sql DESCRIBE your_table_name; Example: sql DESCRIBE employees; SHOW COLUMNS statement: sql SHOW COLUMNS FROM your_table_name; Example: sql SHOW COLUMNS FROM employees; Both of these commands will return information about the columns, such as the column name, data type, whether it allows…

Read More Read More

How to delete a database from mysql server

How to delete a database from mysql server

mysql> drop database databasename; To delete a database from MySQL server, you can use the following SQL command: sql DROP DATABASE [IF EXISTS] database_name; Replace database_name with the name of the database you want to delete. The IF EXISTS clause is optional and prevents an error from occurring if the database does not exist. Here’s an example without the IF EXISTS clause: sql DROP DATABASE mydatabase; And with the IF EXISTS clause: sql DROP DATABASE IF EXISTS mydatabase; Make sure…

Read More Read More

MySQL Interview Questions – Set 14

MySQL Interview Questions – Set 14

Write a query to select all teams that won either 1, 3, 5, or 7 games. SELECT team_name FROM team WHERE team_won IN (1, 3, 5, 7); What is the difference between MySQL and SQL? SQL is known as the standard query language. It is used to interact with the database like MySQL. MySQL is a database that stores various types of data and keeps it safe. A PHP script is required to store and retrieve the values inside the database….

Read More Read More

MySQL Interview Questions – Set 13

MySQL Interview Questions – Set 13

How to join three tables in MySQL? Sometimes we need to fetch data from three or more tables. There are two types available to do these types of joins. Suppose we have three tables named Student, Marks, and Details. Let’s say Student has (stud_id, name) columns, Marks has (school_id, stud_id, scores) columns, and Details has (school_id, address, email) columns. 1. Using SQL Join Clause This approach is similar to the way we join two tables. The following query returns result…

Read More Read More

MySQL Interview Questions – Set 12

MySQL Interview Questions – Set 12

What is the difference between the heap table and the temporary table? Heap tables: Heap tables are found in memory that is used for high-speed storage temporarily. They do not allow BLOB or TEXT fields. Heap tables do not support AUTO_INCREMENT. Indexes should be NOT NULL. Temporary tables: The temporary tables are used to keep the transient data. Sometimes it is beneficial in cases to hold temporary data. The temporary table is deleted after the current client session terminates. Main…

Read More Read More