Found 6702 Articles for Database

Updating a MySQL column that contains dot (.) in its name?

George John
Updated on 30-Jul-2019 22:30:25

870 Views

If the MySQL column contains dot (.) in its name, then you need to use backticks around the column name. To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table UpdateDemo    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> `User.FirstName.LastName` varchar(60)    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into UpdateDemo(`User.FirstName.LastName`) values('John Smith'); Query OK, 1 row affected (0.14 sec) mysql> insert into UpdateDemo(`User.FirstName.LastName`) values('Adam Smith'); Query OK, ... Read More

How to get file extension of file as a result of MySQL query?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

3K+ Views

In order to get file extension of file as a result of SQL query, you can use SUBSTRING_INDEX().The syntax is as followsselect substring_index(yourColumnName, '.', -1) as anyAliasName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table getFileExtensionDemo    -> (    -> File_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> File_Name text    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into getFileExtensionDemo(File_Name) values('John.AllMySQLConcept.doc'); Query OK, 1 row affected (0.17 sec) mysql> ... Read More

How to set all values in a single column MySQL Query?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

10K+ Views

To set all values in a single column MySQL query, you can use UPDATE command.The syntax is as follows.update yourTableName set yourColumnName =yourValue;To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table setAllValuesDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Amount int    -> ); Query OK, 0 rows affected (0.64 sec)Now you can insert some records in the table using insert command.The query is as follows.mysql> insert into setAllValuesDemo(Name, Amount) values('John', 2345); Query OK, 1 row affected ... Read More

How to find strings with a given prefix in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

3K+ Views

You can use LIKE operator to find strings with a given prefix.The syntax is as followsselect *from yourTableName where yourColumnName LIKE 'yourPrefixValue%';To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table findStringWithGivenPrefixDemo    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserMessage text    -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into findStringWithGivenPrefixDemo(UserMessage) values('Hi Good Morning !!!'); Query OK, 1 row affected (0.17 sec) mysql> insert into findStringWithGivenPrefixDemo(UserMessage) values('Hey ... Read More

Convert MySQL null to 0?

George John
Updated on 30-Jul-2019 22:30:25

17K+ Views

Use IFNULL or COALESCE() function in order to convert MySQL NULL to 0.The syntax is as followsSELECT IFNULL(yourColumnName, 0) AS anyAliasName FROM yourTableName; The second syntax is as follows: SELECT COALESCE(yourColumnName, 0) AS anyAliasName FROM yourTableName;Let us first create a table. The query to create a table is as followsmysql> create table convertNullToZeroDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Salary int    -> ); Query OK, 0 rows affected (1.28 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into convertNullToZeroDemo(Name, Salary) values('John', ... Read More

Command to show the database currently being used in MongoDB?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

444 Views

The command to show the database currently used in MongoDB is the following −db;Let us first check how many databases are present. The query is as follows −> show dbs;The following is the output displaying all the databases −admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB studentSearch 0.000GB test 0.003GBNow, we have the list of all databases. Let us use the above syntax to check current database. The query is as follows −> db;The following is the output −sampleLook at the above sample output, we are currently using ‘sample’ database. Let us switch the database and verify again ... Read More

Get the second last row of a table in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:25

10K+ Views

You need to use ORDER BY clause to get the second last row of a table in MySQL.The syntax is as follows.select *from yourTableName order by yourColumnName DESC LIMIT 1, 1;To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table secondLastDemo    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(10)    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command.The query is as follows.mysql> insert into secondLastDemo(StudentName) values('Larry'); Query OK, 1 row affected (0.15 ... Read More

How to SELECT all values from a table only once if they're duplicated?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

6K+ Views

You can use distinct keyword to select all values from a table only once if they are repeated.The syntax is as followsselect distinct yourColumnName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows.mysql> create table displayOnlyDistinctValue    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(100),    -> UserAge int    -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command.The query is as follows.mysql> insert into displayOnlyDistinctValue(UserName, UserAge) values('Larry', 23); Query OK, 1 row affected ... Read More

How to clear console in MongoDB?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

782 Views

To clear console in MongoDB, you can use any of the following two syntaxes.The first syntax is as follows, which is the usage of keyboard shortcut −Ctrl + LAfter pressing the above key, you can clear console in MongoDB.The second syntax is as follows −clsTo understand the above syntaxes, let us implement them one by one. Here is the snapshot of my console.The first query is as follows to clear console in MongoDB −Ctrl+L;The following is the output −Look at the above sample output, the console has been cleared. Let us check the console once again.The second query is as ... Read More

MySQL query to select all entries from a particular month

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

17K+ Views

To select all entries from a particular month in MySQL, use the monthname() or month() function.The syntax is as follows.select *from yourTableName where monthname(yourColumnName)='yourMonthName';To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table selectAllEntriesDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ShippingDate datetime -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into selectAllEntriesDemo(ShippingDate) values('2019-01-21'); Query OK, 1 row affected ... Read More

Advertisements