Found 4381 Articles for MySQL

MySQL query to check if a string contains a value (substring) within the same row?

AmitDiwan
Updated on 24-Sep-2019 12:36:49

1K+ Views

Since we need to match strings from the same row, use LIKE operator. Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    FullName varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 'John Smith'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('David', 'John Miller'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Bob', 'Sam Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Chris', 'Chris Brown'); Query OK, 1 row affected ... Read More

Difference between SQL and NoSQL

Kiran Kumar Panigrahi
Updated on 28-Jul-2022 11:51:45

4K+ Views

Both SQL and NoSQL Databases have their set of advantages and disadvantages. SQL databases can be considered when you are looking for data consistency, reliability, integrity, and when the data is structured. NoSQL databases are a much better option if the data is large, semi-structured, or unstructured and you are looking for faster storage and retrieval of data.With so many databases available in the market, it can get a little challenging for an enterprise to decide whether they should choose an SQL Database or a NoSQL Database. This article will show you the key differences between the two types of ... Read More

Can 'false' match some string in MySQL?

AmitDiwan
Updated on 09-Sep-2019 09:11:53

85 Views

Yes, you can use false as 0 to match.Let us first create a table −mysql> create table DemoTable804 ( Id varchar(100) ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable804 values('101John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable804 values('Carol1002'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable804 values('1000'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable804 values('1010Bob'); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select *from DemoTable804;This ... Read More

Set DEFAULT values for columns while creating a table in MySQL

AmitDiwan
Updated on 09-Sep-2019 09:10:32

2K+ Views

To set default values for columns while creating a table, DEFAULT. Let us first see an example and create a table. As you can see below, while creating the table, we have set DEFAULT −mysql> create table DemoTable803 ( UserId int DEFAULT 101, UserName varchar(100) DEFAULT 'Chris' ); Query OK, 0 rows affected (1.18 sec)Insert some records in the table using insert command. For the values we are not inserting, the default values will get set automatically −mysql> insert into DemoTable803 values(102, 'Chris'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable803(UserName) ... Read More

Display and concatenate records ignoring NULL values in MySQL

AmitDiwan
Updated on 09-Sep-2019 09:08:45

795 Views

Use CONCAT() to concatenate records whereas IFNULL() to check for NULL values.Let us first create a table −mysql> create table DemoTable802 ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command −mysql> insert into DemoTable802 values('Adam', 'Smith'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable802 values('Carol', NULL); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable802 values(NULL, 'Taylor'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable802 values(NULL, NULL); Query OK, 1 row affected (0.21 sec)Display ... Read More

MySQL query to perform sort order on same field

AmitDiwan
Updated on 09-Sep-2019 09:06:18

166 Views

For this, use ORDER BY IF().Let us first create a table −mysql> create table DemoTable801 ( Score int ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable801 values(30); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable801 values(99); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable801 values(45); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable801 values(55); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable801 values(99); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable801 values(69); ... Read More

MySQL select only a single value from 5 similar values?

AmitDiwan
Updated on 09-Sep-2019 09:04:29

205 Views

Let us first create a table −mysql> create table DemoTable800 ( Value int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. Here, we have inserted 5 similar values −mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable800 values(10); Query OK, 1 row affected (0.10 sec)Display all ... Read More

How to concatenate strings using both GROUP_CONCAT() and CONCAT() in the same MySQL query?

AmitDiwan
Updated on 09-Sep-2019 09:03:15

467 Views

The CONCAT() method is used to concat, whereas GROUP_CONCAT() is used to concatenate strings from a group in a single string.Let us first create a table −mysql> create table DemoTable799 ( UserId int, UserName varchar(100), UserAge int ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable799 values(101, 'John', 21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable799 values(102, 'Chris', 26); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable799 values(101, 'Robert', 23); Query OK, 1 ... Read More

Why the #1054 - Unknown column error occurs in MySQL and how to fix it?

AmitDiwan
Updated on 09-Sep-2019 09:01:35

3K+ Views

Let’s see when the #1054 error occurs in MySQL. While inserting a varchar value, if you will forget to add single quotes, then this error will arise. Following is the error −mysql> insert into DemoTable798 values(100, Adam); ERROR 1054 (42S22): Unknown column 'Adam' in 'field list'You need to use single quotes around the string value to fix this error as shown below −mysql> insert into DemoTable798 values(100, ’Adam’);Let us first create a table −mysql> create table DemoTable798 ( StudentId int, StudentName varchar(100) ); Query OK, 0 rows affected (0.51 sec)Insert some records in the ... Read More

What is the correct DateTime format for a MySQL Database?

AmitDiwan
Updated on 09-Sep-2019 08:59:55

252 Views

The correct datetime format for MySQL database is as follows −‘YYYY-MM-DD HH:M:SS’Let us first create a table −mysql> create table DemoTable797 ( ArrivalDatetime datetime ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable797 values(NOW()); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable797 values('2016-12-21 12:50:34'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable797 values('2017-03-01 17:40:21'); Query OK, 1 row affected (0.24 sec)Display all records from the table using select statement −mysql> select *from DemoTable797;This will produce the following output. We have ... Read More

Advertisements