Found 4219 Articles for MySQLi

Insert Euro and Dollar symbol to a column in MySQL?

AmitDiwan
Updated on 27-Dec-2019 06:15:28

1K+ Views

For this, use CASE statement with UPDATE command. Let us first create a table −mysql> create table DemoTable1874    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Amount varchar(100) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1874(Amount) values('3450'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('190'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('7600'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1874(Amount) values('4500'); Query OK, 1 row affected (0.00 sec)Display all records ... Read More

Best way to update a single column in a MySQL table?

AmitDiwan
Updated on 27-Dec-2019 06:11:45

323 Views

To update a single column, use UPDATE and SET as in the below syntax −update yourTableName set yourColumnName=yourValue;Let us first create a table −mysql> create table DemoTable1873      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      FirstName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1873(FirstName) values('John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1873(FirstName) values('Adam'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1873(FirstName) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into ... Read More

MySQL query to SELECT rows with LIKE and create new column containing the matched string?

AmitDiwan
Updated on 27-Dec-2019 06:09:28

205 Views

For this, use SUBSTRING(). Let us first create a table −mysql> create table DemoTable1872    (    Name varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1872 values('John Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1872 values('Adam Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1872 values('Mitchell Johnson'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1872;This will produce the following output −+------------------+ | Name         ... Read More

MySQL Datetime to add days?

AmitDiwan
Updated on 27-Dec-2019 06:05:40

176 Views

Let us first create a table −mysql> create table DemoTable1871      (      ArrivalDate datetime      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1871 values('2019-12-19 7:45:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1871 values('2018-11-10 12:00:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1871 values('2019-01-31'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1871; This will produce the following output −+---------------------+ | ArrivalDate         | ... Read More

Get first date from timestamp in MySQL group by another column with duplicate value

AmitDiwan
Updated on 27-Dec-2019 06:04:31

238 Views

For this, you can use aggregate function MIN() and GROUP BY. Let us first create a table −mysql> create table DemoTable1870      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      Value int,      ShippingTimestamp varchar(100)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(10, '1570645800'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(10, '1546194600'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1870(Value, ShippingTimestamp) values(11, '1573324200'); Query OK, 1 row affected (0.00 ... Read More

Concatenate two values from the same column with different conditions in MySQL

AmitDiwan
Updated on 26-Dec-2019 07:35:39

902 Views

For this, you can use group_concat() with aggregate function. Let us first create a table −mysql> create table DemoTable1869      (      Id int,      Subject varchar(20 ),      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1869 values(100, 'MySQL', 'John'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1869 values(100, 'MongoDB', 'Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1869 values(101, 'MySQL', 'Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1869 values(101, ... Read More

How to derive value of a field from another field in MySQL?

AmitDiwan
Updated on 26-Dec-2019 07:31:05

317 Views

For this, you can use the concept of user defined variable. Let us first create a table −mysql> create table DemoTable1868      (      Value int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1868 values(10); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(20); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(30); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1868 values(40); Query OK, 1 row affected (0.00 sec)Display all records from the table using ... Read More

How to list all variables initialized by SET operator in MySQL?

AmitDiwan
Updated on 26-Dec-2019 07:22:55

237 Views

To list all variables initialized by SET operator, the syntax is as follows −select * from performance_schema.user_variables_by_thread;Here is the query to set the variable −mysql> set @FirstName='John'; Query OK, 0 rows affected (0.00 sec) mysql> set @LastName='Doe'; Query OK, 0 rows affected (0.00 sec)Here is the query to display the list of all variables initialized by SET operator. This list includes the variables set above −mysql> select * from performance_schema.user_variables_by_thread;This will produce the following output −+-----------+---------------+----------------+ | THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE | +-----------+---------------+----------------+ |       120 | TotalAmount   |           5000 | ... Read More

Increment date/time value by second with MySQL query?

AmitDiwan
Updated on 26-Dec-2019 07:21:06

459 Views

For this, use date_add() with interval command. Let us first create a table −mysql> create table DemoTable1867      (      ArrivalTime datetime      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1867 values('2019-10-12 12:34:45'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 10:04:15'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1867 values('2019-10-12 11:00:23'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1867; This will produce the following output ... Read More

MySQL query to get string from one column and find its position in another column with comma separated values?

AmitDiwan
Updated on 26-Dec-2019 07:19:48

257 Views

For this, use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1866      (      Value1 int,      ListOfValues varchar(100)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1866 values(56, '78, 56, 98, 95'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1866 values(103, '103, 90, 102, 104'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1866 values(77, '34, 45, 77, 78'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> ... Read More

Advertisements