MySQL Articles

Page 110 of 355

Update only a single column value in MySQL

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 346 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

How to ignore specific records and add remaining corresponding records (numbers) in MySQL?

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 159 Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(20),    -> Amount int    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John', 200); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Chris', 150); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Mike', 500); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('John', 350); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> ...

Read More

Update with multiple values in MySQL WHERE clause

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 2K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20),    -> Age int,    -> CountryName varchar(10)    -> ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris', 34, 'AUS'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(101, 'Chris', 31, 'US'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(102, 'David', 25, 'UK'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(103, 'Carol', 28, 'AUS'); ...

Read More

Working with WHERE IN() in a MySQL Stored Procedure

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 1K+ Views

Let us first create a table −mysql> create table DemoTable    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(101, 'Bob'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(102, 'David'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select * from DemoTable;This will produce the following output −+------+-------+ | Id   ...

Read More

How to sum cells in a column if a condition is met in another column with MySQL?

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 1K+ Views

For this, you can use the aggregate function SUM() along with the GROUP BY clause. Let us first create a table −mysql> create table DemoTable    -> (    -> EmployeeName varchar(20),    -> JoiningDate date,    -> Salary int    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('David', '2019-11-02', 400); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable values('Robert', '2018-11-25', 100); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable values('Bob', '2019-12-14', 600); Query OK, 1 row affected (0.25 sec) ...

Read More

Add records from corresponding duplicate values in another column with MySQL

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 282 Views

For this, you can use the aggregate function SUM() along with the GROUP BY clause. Let us first create a table −mysql> create table DemoTable    -> (    -> Name varchar(20),    -> Value int    -> ); Query OK, 0 rows affected (2.08 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 50); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('David', 90); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris', 60); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Bob', 100); Query ...

Read More

UPDATE with logical AND operator in MySQL

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 481 Views

For this, you can use AND operator with WHERE clause. Let us first create a table −mysql> create table DemoTable1616     -> (     -> StudentId int,     -> StudentName varchar(20),     -> StudentMarks int     -> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1616 values(101, 'Chris', 56); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1616 values(102, 'Bob', 87); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1616 values(103, 'David', 56); Query OK, 1 row affected (0.20 sec) ...

Read More

How to get the count of both present and absent students for a year in MySQL?

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 1K+ Views

For this, you can use IF() along with aggregate function SUM(). Let us first create a table −mysql> create table DemoTable1617     -> (     -> Attendance varchar(20),     -> CurrentYear int     -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1617 values('Present', 2019); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1617 values('Absent', 2019); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1617 values('Absent', 2017); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1617 values('Present', 2019); Query ...

Read More

Select total from a MySQL table based on month

AmitDiwan
AmitDiwan
Updated on 28-Feb-2020 311 Views

For this, you can use GROUP BY MONTH(). Let us first create a table −mysql> create table DemoTable1628     -> (     -> PurchaseDate date,     -> Amount int     -> ); Query OK, 0 rows affected (1.55 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1628 values('2019-01-10', 1500); Query OK, 1 row affected (0.68 sec) mysql> insert into DemoTable1628 values('2019-10-10', 2000); Query OK, 1 row affected (0.61 sec) mysql> insert into DemoTable1628 values('2019-10-24', 100); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1628 values('2019-11-10', 500); Query OK, 1 row affected ...

Read More

What happens to the current MySQL transaction if the session is killed by DBA?

Swarali Sree
Swarali Sree
Updated on 27-Feb-2020 783 Views

Suppose if a session is killed in the middle of a transaction then that current MySQL transaction will be rolled back by MySQL and ended. It means that all the database changes made in the current transaction will be removed. It is called n implicit rollback when the session is killed.ExampleSuppose we have the following values in the table ‘marks’mysql> Select * from marks; +------+---------+-----------+-------+ | Id   | Name    | Subject   | Marks | +------+---------+-----------+-------+ |    1 | Aarav   | Maths     |    50 | |    1 | Harshit | Maths   ...

Read More
Showing 1091–1100 of 3,547 articles
« Prev 1 108 109 110 111 112 355 Next »
Advertisements