Found 4219 Articles for MySQLi

MySQL query to find a value in a set of values separated by comma in a custom variable

AmitDiwan
Updated on 12-Nov-2019 05:12:02

176 Views

For this, use FIND_IN_SET() in MySQL and use the value from a custom variable. Let us first create a −mysql> create table DemoTable1411    -> (    -> Value int    -> )    -> ; Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert −mysql> insert into DemoTable1411 values(10); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1411 values(50); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1411 values(60); Query OK, 1 row affected (0.08 sec)Display all records from the table using select −mysql> select * from DemoTable1411;This will produce ... Read More

How to mask data fields in MySQL?

AmitDiwan
Updated on 12-Nov-2019 05:08:56

1K+ Views

To mask data fields, use CONCAT() along with REPEAT(). Here, we will mask data fields with #. Let us first create a −mysql> create table DemoTable1410    -> (    -> Password varchar(80)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert −mysql> insert into DemoTable1410 values('John12345678'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1410 values('Carol_897'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1410 values('David_5647383'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select −mysql> select * from DemoTable1410;This will produce ... Read More

How to add duplicate varchar values without displaying error in MySQL?

AmitDiwan
Updated on 11-Nov-2019 11:08:27

70 Views

For this, let us see an example and first create a −mysql> create table DemoTable1409    -> (    -> FirstName varchar(20),    -> UNIQUE KEY UN_FirstName(FirstName)    -> ); Query OK, 0 rows affected (0.79 sec)Following is the query to add duplicate varchar −mysql> alter table DemoTable1409 drop index  UN_FirstName; Query OK, 0 rows affected (0.40 sec) Records: 0  Duplicates: 0  Warnings: 0Insert some records in the table using insert −mysql> insert into DemoTable1409 values('Chris'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1409 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1409 values('David'); ... Read More

How to include quotes in comma separated column with MySQL?

AmitDiwan
Updated on 11-Nov-2019 11:04:22

731 Views

Let us first create a −mysql> create table DemoTable1407    -> (    -> Name text    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert −mysql> insert into DemoTable1407 values('John, Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1407 values('Carol, David, Adam'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1407 values('Mike, Sam, Chris'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select −mysql> select * from DemoTable1407;This will produce the following output −+------------------+ | Name             ... Read More

Using the entire expression in MySQL WHERE clause?

AmitDiwan
Updated on 11-Nov-2019 11:02:48

74 Views

Let us see an example and create a −mysql> create table DemoTable1406    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert −mysql> insert into DemoTable1406 values(10); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1406 values(50); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1406 values(40); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable1406 values(30); Query OK, 1 row affected (0.11 sec)Display all records from the table using select −mysql> select * from DemoTable1406;This will produce the following ... Read More

Update all rows in MySQL and remove all the unnecessary whitespaces in and around the string?

AmitDiwan
Updated on 11-Nov-2019 11:01:29

64 Views

To remove unnecessary whitespaces, use TRIM() in MySQL. Let us first create a −mysql> create table DemoTable1405    -> (    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert −mysql> insert into DemoTable1405 values('   Chris', ' Brown '); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1405 values('David      ', ' Miller '); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1405 values('     Carol ', ' Taylor '); Query OK, 1 row affected (0.19 sec)Display all ... Read More

Display month names and year from a column with date records with MySQL

AmitDiwan
Updated on 11-Nov-2019 10:57:08

379 Views

Let us first create a −mysql> create table DemoTable1619    -> (    -> ArrivalTime datetime    -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert −mysql> insert into DemoTable1619 values(now()); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable1619 values(curdate()); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1619 values('2019-12-31'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select −mysql> select * from DemoTable1619;This will produce the following output −+---------------------+ | ArrivalTime         | +---------------------+ | 2019-10-20 15:02:12 | | ... Read More

MySQL query to copy IP address from varchar column to integer in the same table?

AmitDiwan
Updated on 11-Nov-2019 10:55:05

193 Views

For this, you can use INET_ATON(). Let us first create a −mysql> create table DemoTable1404    -> (    -> IpAddress varchar(40)    -> ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert −mysql> insert into DemoTable1404 values('192.168.120.0'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable1404 values('192.168.120.20'); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable1404 values('224.0.0.0'); Query OK, 1 row affected (0.42 sec)Display all records from the table using select −mysql> select * from DemoTable1404;This will produce the following output −+----------------+ | IpAddress      | +----------------+ | ... Read More

Update table and order dates in MySQL

AmitDiwan
Updated on 11-Nov-2019 10:52:35

322 Views

You cannot use UPDATE command with ORDER BY clause, but you can use SELECT statement with ORDER BY DESC.Let us first create a −mysql> create table DemoTable1403    -> (    -> DueDate timestamp    -> ); Query OK, 0 rows affected (1.26 sec)Insert some records in the table using insert −mysql> insert into DemoTable1403 values('2019-09-29'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable1403 values('2016-02-21'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable1403 values('2018-01-31'); Query OK, 1 row affected (0.65 sec) mysql> insert into DemoTable1403 values('2017-12-01'); Query OK, 1 row affected (0.27 sec)Display all ... Read More

Display substring in MySQL if the string is less than a specific length or display a custom message if it is more?

AmitDiwan
Updated on 11-Nov-2019 10:50:57

113 Views

For this, you can use substring() function in MySQL. For conditions, use MySQL CASE statement. Let us first create a −mysql> create table DemoTable1402    -> (    -> EmployeeName varchar(40)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert −mysql> insert into DemoTable1402 values('Adam Smith'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1402 values('Chris Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1402 values('David Miller'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1402 values('Carol Taylor'); Query OK, 1 row affected (0.10 sec)Display ... Read More

Advertisements