Found 4219 Articles for MySQLi

Display different variables in MySQL using LIKE?

Kumar Varma
Updated on 30-Jul-2019 22:30:26

88 Views

Following is the syntax −show variables where Variable_name like 'yourVariable1%' or Variable_name like 'yourVariable2%', .............N;Let us implement the above syntax to show(more than one) variables −mysql> show variables where Variable_name like 'key%' or Variable_name like 'innodb_undo%' or Variable_name like 'innodb_log%';Output+------------------------------------+----------+ | Variable_name                      | Value | +------------------------------------+----------+ | innodb_log_buffer_size             | 1048576 | | innodb_log_checksums               | ON | | innodb_log_compressed_pages        | ON ... Read More

How to update a timestamp field of a MySQL table?

Rama Giri
Updated on 30-Jul-2019 22:30:26

2K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> PunchOut timestamp,    -> PunchStatus tinyint(1)    -> ); Query OK,  0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-31 6:30:10', 1); Query OK,  1 row affected (0.22 sec) mysql> insert into DemoTable values('2019-02-06 4:10:13', 0); Query OK,  1 row affected (0.14 sec) mysql> insert into DemoTable values('2018-12-16 03:00:30', 0); Query OK,  1 row affected (0.16 sec) mysql> insert into DemoTable values('2016-11-25 02:10:00', 1); Query OK,  1 row affected (0.22 sec)Display all records from the table using select statemen −mysql> select *from DemoTable;Output+---------------------+-------------+ | PunchOut            | PunchStatus | +---------------------+-------------+ | 2019-01-31 06:30:10 |           1 | | 2019-02-06 04:10:13 |           0 | | 2018-12-16 03:00:30 | ... Read More

MySQL query to return only the rows which are numeric?

Kumar Varma
Updated on 30-Jul-2019 22:30:26

771 Views

Use REGEXP to return only the numeric rows. Let us first create a table −mysql> create table DemoTable    -> (    -> StudentId varchar(100)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John74747'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('8494575Carol'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('985755645'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Carol-9032'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('101'); ... Read More

What is the most efficient way to select a specific number of random rows in MySQL?

Rama Giri
Updated on 30-Jul-2019 22:30:26

431 Views

Use RAND() method for random and to limit a number of records, use the LIMIT() method in MySQL.Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(300); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(600); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(700); Query OK, 1 row ... Read More

How can I find the percentage of my users whose birth date is between 1980 and 1996 in MySQL?

Kumar Varma
Updated on 30-Jul-2019 22:30:26

97 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> DateOfBirth varchar(100)    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019/01/31'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('1980/02/01'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('1985/04/10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('1995/06/04'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('1990/12/24'); Query OK, 1 row affected (0.18 sec) ... Read More

How to place a thousand separator in MySQL records?

Rama Giri
Updated on 30-Jul-2019 22:30:26

1K+ Views

Use the FORMAT() method for this. Let us first create a table −mysql> create table DemoTable    -> (    -> Amount DECIMAL(10, 2)    -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(84848757.60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(95868685.50); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(4242342.36); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+-------------+ | Amount      | +-------------+ | 84848757.60 ... Read More

How to perform update in MySQL to disallow incrementing all the values above a specific value?

Kumar Varma
Updated on 30-Jun-2020 11:09:06

56 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(150); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(180); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(200); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+-------+ | Value ... Read More

MySQL query to get the count of values and display the count in a new column ordered in descending order

Rama Giri
Updated on 30-Jul-2019 22:30:26

4K+ Views

Use ORDER BY with DESC to order in descending order. For counting the values, use the COUNT(). For example, if the name “John” appears thrice in the column, then a separate column will display the count 3 and in this way all the count values will be arranged in descending order using the ORDER BY DESC.Let us first create a table −mysql> create table DemoTable -> ( -> EmployeeName varchar(100) -> ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable ... Read More

Getting the maximum value from a varchar field in MySQL

Kumar Varma
Updated on 30-Jul-2019 22:30:26

156 Views

Use MAX() function along with SUBSTRING() for this. Let us first create a table −mysql> create table DemoTable    -> (    -> Id varchar(200)    -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-0515-1980'); Query OK, 1 row affected (0.49 sec) mysql> insert into DemoTable values('2019-0516-780'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-0517-2780'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+----------------+ | Id           ... Read More

GROUP BY and display only non-empty column values in MySQL

Rama Giri
Updated on 30-Jul-2019 22:30:26

1K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id varchar(100),    -> Message varchar(200)    -> ); Query OK, 0 rows affected (1.17 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('1', ''); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('1', 'Hi'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('2', 'Hello'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('3', 'Awesome'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('3', ... Read More

Advertisements