MySQL Articles

Page 148 of 355

How to use CONTAINS() with CURDATE in MySQL?

AmitDiwan
AmitDiwan
Updated on 24-Dec-2019 241 Views

For this, you can use CONCAT() with CURDATE().There is no function with the name CONTAINS() in MySQL.Let us first get the current date. The current date is as follows −mysql> select curdate();This will produce the following output −+------------+ | curdate()  | +------------+ | 2019-11-28 | +------------+ 1 row in set (0.00 sec)We will now create a table −mysql> create table DemoTable1803      (      Name varchar(20),      JoiningYear varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1803 values('Chris', '2020/2017'); Query OK, 1 row ...

Read More

MySQL group by for separate id without using GROUP BY to remove duplicate column row?

AmitDiwan
AmitDiwan
Updated on 24-Dec-2019 175 Views

For this, you can use DISTINCT keyword. Let us first create a table −mysql> create table DemoTable1801      (      Name varchar(20),      Score int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1801 values('John', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John', 99); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('Carol', 99); Query OK, 1 row affected (0.00 sec)Display all records ...

Read More

Find sum with MySQL SUM() and give aliases for column heading

AmitDiwan
AmitDiwan
Updated on 23-Dec-2019 575 Views

For alias, use the following syntax wherein we are display an alias name −select sum(yourColumnName) as anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable1800      (      Salary int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1800 values(18000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1800 values(32000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1800 values(50000); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * ...

Read More

How to quote values of single column using GROUP_CONCAT and CONCAT with DISTINCT in MySQL?

AmitDiwan
AmitDiwan
Updated on 23-Dec-2019 550 Views

For this, you can use group_concat() along with replace(). Let us first create a table −mysql> create table DemoTable1799      (      EmployeeId varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1799 values('101, 102, 103, 104'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1799 values('106, 109'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1799;This will produce the following output:+-----------------+ | EmployeeId      | +-----------------+ | 101, 102, 103, ...

Read More

How to display two different sums of the same price from column Amount in MySQL?

AmitDiwan
AmitDiwan
Updated on 23-Dec-2019 208 Views

For this, you can use case statement. Let us first create a table −mysql> create table DemoTable1794      (      Amount int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1794 values(100); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1794 values(80); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1794 values(320); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1794;This will produce the following output −+--------+ | Amount | ...

Read More

How do I select data that does not have a null record in MySQL?

AmitDiwan
AmitDiwan
Updated on 23-Dec-2019 144 Views

To select not-null records, use IS NOT NULL property. Let us first create a table −mysql> create table DemoTable1792      (      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1792 values('John Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1792 values(NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1792 values('David Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1792 values(NULL); Query OK, 1 row affected (0.00 sec)Display all records from the table using ...

Read More

Get multiple count in a single MySQL query for specific column values

AmitDiwan
AmitDiwan
Updated on 23-Dec-2019 751 Views

For this, you can use aggregate function sum() along with parameter value for specific column. Let us first create a table −mysql> create table DemoTable1790      (      Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,      Name varchar(20),      Score int      ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1790(Name, Score) values('Chris', 45); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1790(Name, Score) values('David', 55); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1790(Name, Score) values('David', 98); Query OK, ...

Read More

How to display first day and last day of the month from date records in MySQL?

AmitDiwan
AmitDiwan
Updated on 18-Dec-2019 339 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-11'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('2019-04-19'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------+ | DueDate    | +------------+ | 2019-01-11 | | 2019-04-19 | +------------+ 2 rows in set (0.00 sec)Following is the query to display ...

Read More

Get database name from a query implemented in a MySQL Stored Procedure?

AmitDiwan
AmitDiwan
Updated on 18-Dec-2019 366 Views

To get the database name, use the below given syntax −select database();Let us implement the above syntax in the stored procedure −mysql> delimiter // mysql> create procedure get_procedure_database_name()    -> begin    -> select concat('The database name=',database());    -> end    -> // Query OK, 0 rows affected (0.34 sec) mysql> delimiter ;Now you can call a stored procedure using CALL command −mysql> call get_procedure_database_name();This will produce the following output −+-----------------------------------------+ | concat('The database name=',database()) | +-----------------------------------------+ | The database name=web                   | +-----------------------------------------+ 1 row in set (0.05 sec) Query OK, 0 rows affected (0.08 sec)

Read More

Select and sum with grouping in MySQL?

AmitDiwan
AmitDiwan
Updated on 18-Dec-2019 663 Views

To sum, use the aggregate function SUM(). With that, group using MySQL GROUP BY. Let us first create a table −mysql> create table DemoTable    -> (    -> ProductName varchar(20),    -> ProductQuantity int,    -> ProductPrice int    -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1', 2, 50); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Product-2', 3, 80); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Product-2', 4, 100); Query OK, 1 row affected (0.11 sec) mysql> ...

Read More
Showing 1471–1480 of 3,543 articles
« Prev 1 146 147 148 149 150 355 Next »
Advertisements