Found 4219 Articles for MySQLi

Format MySQL records (price values) after multiplying them

AmitDiwan
Updated on 17-Dec-2019 05:36:53

159 Views

To format records, use FORMAT(). Let us first create a table −mysql> create table DemoTable    -> (    -> Price decimal(10, 4),    -> Rate decimal(10, 4)    -> ); Query OK, 0 rows affected (0.96 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1000, 10.2); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(2000, 20.4); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(100, 5); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

MySQL LIKE command doesn't work with strings containing dots to display records beginning with a specific number

AmitDiwan
Updated on 17-Dec-2019 05:34:46

336 Views

To work with strings containing dots, and display records beginning with a specific number, you need to use REGEXP. Let us first create a table −mysql> create table DemoTable    -> (    -> GameReleaseVersion varchar(20)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('19.6'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('18.4'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('17.6'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('19.5'); Query OK, 1 row affected ... Read More

MySQL query to fetch records before currentdate + 2 weeks?

AmitDiwan
Updated on 16-Dec-2019 07:57:57

575 Views

For this, use the below syntax −select * from yourTableName where yourColumnName < DATE_ADD(CURDATE(), INTERVAL 2 WEEK);Note: The current date is as follows −mysql> select curdate(); +------------+ | curdate()  | +------------+ | 2019-10-20 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable1607    -> (    -> ShippingDate date    -> )    -> ; Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1607 values('2019-10-20'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1607 values('2019-11-04'); Query OK, 1 row affected ... Read More

Implement Harmonic mean and Quadratic mean in MySQL?

AmitDiwan
Updated on 16-Dec-2019 07:43:05

99 Views

Let us first create a table −mysql> create table DemoTable1606    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1606 values(5); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1606 values(10); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select * from DemoTable1606;This will produce the following output −+-------+ | Value | +-------+ |     5 | |    10 | +-------+ 2 rows in set (0.00 sec)Here is the ... Read More

How to correctly implement conditions in MySQL stored procedure?

AmitDiwan
Updated on 16-Dec-2019 07:42:00

155 Views

To set conditions in stored procedure, use the below syntax −    if yourCondition then    yourStatement1;      else    yourStatement2';       end if ;     end     //Let us implement the above syntax in order to correct missing semicolon in stored procedure −mysql> delimiter // mysql> create procedure Test_Demo(In inputValue int)    -> BEGIN    -> if inputValue=10 then    -> select 'You have won 100$';    -> else    -> select 'Sorry !!!';     -> end if ;     -> end     -> // Query OK, 0 rows affected (0.20 ... Read More

Update only a single column value in MySQL

AmitDiwan
Updated on 28-Feb-2020 10:37:11

229 Views

Let us first create a table −mysql> create table DemoTable1605    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20),    -> StudentCountryName varchar(20)    -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1605(StudentName, StudentCountryName) values('Adam', 'AUS'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1605(StudentName, StudentCountryName) values('John', 'US'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1605(StudentName, StudentCountryName) values('Bob', 'UK'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select ... Read More

Convert string (varchar) to timestamp format in MySQL?

AmitDiwan
Updated on 16-Dec-2019 07:37:06

3K+ Views

To convert string to timestamp format, use STR_TO_DATE() along with DATE_FORMAT(). Let us first create a table −mysql> create table DemoTable1602    -> (    -> ReportingDate varchar(40)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1602 values('Wed Oct 02 16:10:45 IST 2019'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1602 values('Fri May 31 13:00:10 IST 2019'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1602 values('Mon Dec 31 14:20:00 IST 2018'); Query OK, 1 row affected (0.23 sec)Display all records from ... Read More

MySQL update column to NULL for blank values

AmitDiwan
Updated on 16-Dec-2019 07:35:34

2K+ Views

For this, you can use IF() along with UPDATE command. Let us first create a table −mysql> create table DemoTable1601    -> (    -> FirstName varchar(20) ,    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1601 values('John', 'Doe'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1601 values('Adam', ''); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1601 values('David', 'Miller'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1601 values('Chris', ''); Query OK, 1 row affected ... Read More

Can I query how much disk space certain rows or columns are taking up in MySQL?

AmitDiwan
Updated on 10-Jul-2020 14:06:46

440 Views

Yes, using the below syntax −select * from information_schema.tables where table_name=yourTableName;Let us first create a table −mysql> create table DemoTable1600    -> (    -> StudentId int,    -> StudentFirstName varchar(20)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1600 values(100, 'Bob'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1600 values(101, 'David'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1600 values(102, 'Carol'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select * from ... Read More

How to MySQL SELECT by month?

AmitDiwan
Updated on 16-Dec-2019 07:30:45

352 Views

To select by month, use MONTH() function. Let us first create a table −mysql> create table DemoTable1599    -> (    -> Shippingdate datetime    -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1599 values('2019-10-21'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1599 values('2018-12-12'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable1599 values('2015-11-21'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1599 values('2017-12-31'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1599 values('2018-12-26'); Query OK, 1 row affected ... Read More

Advertisements