Browsed by
Category: Blog

How to update the table in MySQL?

How to update the table in MySQL?

We can update existing records in a table using the UPDATE statement that comes with the SET and WHERE clauses. The SET clause changes the values of the specified column. The WHERE clause is optional, which is used to specify the condition. This statement can also use to change values in one or more columns of a single row or multiple rows at a time. Following is a generic syntax of UPDATE command to modify data into the MySQL table:…

Read More Read More

How to find the second highest salary in MySQL?

How to find the second highest salary in MySQL?

MySQL uses the LIMIT keyword, which can be used to limit the result set. It will allow us to get the first few rows, last few rows, or range of rows. It can also be used to find the second, third, or nth highest salary. It ensures that you have use order by clause to sort the result set first and then print the output that provides accurate results. The following query is used to get the second highest salary…

Read More Read More

What is the difference between UNIX timestamps and MySQL timestamps?

What is the difference between UNIX timestamps and MySQL timestamps?

Actually, both Unix timestamp and MySQL timestamp are stored as 32-bit integers, but MySQL timestamp is represented in the readable format of YYYY-MM-DD HH:MM:SS format. UNIX timestamps and MySQL timestamps are both used to represent points in time, but they differ in their formats and usage: UNIX Timestamps: UNIX timestamps, also known as epoch time or POSIX time, represent the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. They are represented as a single integer value,…

Read More Read More

How is the MyISAM table stored?

How is the MyISAM table stored?

MyISAM table is stored on disk in three formats. ‘.frm’ file : storing the table definition ‘.MYD’ (MYData): data file ‘.MYI’ (MYIndex): index file MyISAM tables in MySQL are stored as three types of files on the disk: .frm file: This file stores the table definition. .MYD file: This file contains the data. .MYI file: This file holds the index data. Each of these files is crucial for the functioning of a MyISAM table.

What are DDL, DML, and DCL?

What are DDL, DML, and DCL?

Majorly SQL commands can be divided into three categories, i.e., DDL, DML & DCL. Data Definition Language (DDL) deals with all the database schemas, and it defines how the data should reside in the database. Commands like CreateTABLE and ALTER TABLE are part of DDL. Data Manipulative Language (DML) deals with operations and manipulations on the data. The commands in DML are Insert, Select, etc. Data Control Languages (DCL) are related to the Grant and permissions. In short, the authorization…

Read More Read More

MySQL Interview Questions – Set 10

MySQL Interview Questions – Set 10

How to change the table name in MySQL? Sometimes our table name is non-meaningful. In that case, we need to change or rename the table name. MySQL provides the following syntax to rename one or more tables in the current database: mysql> RENAME old_table TO new_table; If we want to change more than one table name, use the below syntax: RENAME TABLE old_tab1 TO new_tab1, old_tab2 TO new_tab2, old_tab3 TO new_tab3; How to set auto increment in MySQL? Auto Increment is a constraint that automatically generates a unique number while…

Read More Read More

Why do we use the MySQL database server?

Why do we use the MySQL database server?

First of all, the MYSQL server is free to use for developers and small enterprises. MySQL server is open source. MySQL’s community is tremendous and supportive; hence any help regarding MySQL is resolved as soon as possible. MySQL has very stable versions available, as MySQL has been in the market for a long time. All bugs arising in the previous builds have been continuously removed, and a very stable version is provided after every update. The MySQL database server is…

Read More Read More

What is MySQL Workbench?

What is MySQL Workbench?

MySQL Workbench is a unified visual database designing or GUI tool used for working on MySQL databases. It is developed and maintained by Oracle that provides SQL development, data migration, and comprehensive administration tools for server configuration, user administration, backup, etc. We can use this Server Administration to create new physical data models, E-R diagrams, and SQL development. It is available for all major operating systems. MySQL provides supports for it from MySQL Server version v5.6 and higher. It is…

Read More Read More

What is the difference between TRUNCATE and DELETE in MySQL?

What is the difference between TRUNCATE and DELETE in MySQL?

TRUNCATE is a DDL command, and DELETE is a DML command. It is not possible to use Where command with TRUNCATE QLbut you can use it with DELETE command. TRUNCATE cannot be used with indexed views, whereas DELETE can be used with indexed views. The DELETE command is used to delete data from a table. It only deletes the rows of data from the table while truncate is a very dangerous command and should be used carefully because it deletes…

Read More Read More

How to display the nth highest salary from a table in a MySQL query?

How to display the nth highest salary from a table in a MySQL query?

Let us take a table named the employee. To find Nth highest salary is: select distinct(salary)from employee order by salary desc limit n-1,1 if you want to find 3rd largest salary: select distinct(salary)from employee order by salary desc limit 2,1 To display the nth highest salary from a table in MySQL, you can use the following query: SELECT salary FROM employees ORDER BY salary DESC LIMIT n-1, 1; Replace employees with the name of your table and salary with the…

Read More Read More