MySQL Articles

Page 268 of 355

How to add some days to str_to_date() MySQL function?

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 197 Views

You can use DATE_ADD() function from MySQL. Let us first create a table −mysql> create table DemoTable    -> (    -> ShippingDate varchar(100)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('06-01-2019'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('01-04-2017'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('29-06-2019'); Query OK, 1 row affected (0.47 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+--------------+ | ShippingDate | +--------------+ | 06-01-2019   | ...

Read More

MySQL query to replace a string after the last / in a column with directory links?

Rama Giri
Rama Giri
Updated on 30-Jul-2019 183 Views

For this, use the substring_index() method. Let us first create a table −mysql> create table DemoTable    -> (    -> FolderName varchar(100),    -> FolderLocation varchar(200)    -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('CProgram', 'C:/AllPrograms/.....'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Images', 'E:/MyImage/home/garbage'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------+-------------------------+ | FolderName | FolderLocation          | +------------+-------------------------+ | CProgram   | C:/AllPrograms/.....   ...

Read More

How to show GRANTS for root in MySQL?

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 190 Views

For this, use the following syntax, wherein we have used SHOW GRANTS −SHOW GRANTS FOR 'yourUserName'@'yourHostName';HostName may be ‘%’ or localhost.Let us implement the above syntax in order to show grants from ROOT −mysql> SHOW GRANTS FOR 'root'@'%' ;Output+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Grants for root@%                                                                                                                   ...

Read More

Select dates between current date and 3 months from the current date in MySQL?

Rama Giri
Rama Giri
Updated on 30-Jul-2019 2K+ Views

Use BETWEEN and INTERVAL to achieve this. Let us first create a table −mysql> create table DemoTable    -> (    -> AdmissionDate date    -> ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable  values('2019-09-30'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable  values('2019-10-01'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable  values('2019-03-30'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable  values('2019-04-24'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select ...

Read More

Update multiple columns of a single row MySQL?

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 613 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> FirstName varchar(100),    -> Age int,    -> Score int    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Robert', 21, 78); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Bob', 20, 90); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Sam', 22, 69); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+-----------+------+-------+ | ...

Read More

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

Rama Giri
Rama Giri
Updated on 30-Jul-2019 2K+ 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

Getting the maximum value from a varchar field in MySQL

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 264 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

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

Rama Giri
Rama Giri
Updated on 30-Jul-2019 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

How to place a thousand separator in MySQL records?

Rama Giri
Rama Giri
Updated on 30-Jul-2019 2K+ 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 can I find the percentage of my users whose birth date is between 1980 and 1996 in MySQL?

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 161 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
Showing 2671–2680 of 3,547 articles
« Prev 1 266 267 268 269 270 355 Next »
Advertisements