MySQL Forums
Forum List  »  Newbie

Re: Update with Logical Operator
Posted by: Barry Galbraith
Date: January 03, 2023 05:51PM

CREATE DATABASE `test`;

USE `test`;

/*Table structure for table `memberdetails` */

DROP TABLE IF EXISTS `memberdetails`;

CREATE TABLE `memberdetails` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  `street` varchar(20) DEFAULT NULL,
  `city` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ;

/*Data for the table `memberdetails` */

insert  into `memberdetails`(`id`,`name`,`street`,`city`)
values (1,'Fred','Old Street','Bedrock')
,(2,'Barney','Old Street','Bedrock')
,(3,'Slate','Other Street','Bedrock');

SELECT * from memberdetails;
+----+--------+--------------+---------+
| id | name   | street       | city    |
+----+--------+--------------+---------+
|  1 | Fred   | Old Street   | Bedrock |
|  2 | Barney | Old Street   | Bedrock |
|  3 | Slate  | Other Street | Bedrock |
+----+--------+--------------+---------+
3 rows in set (0.00 sec)

UPDATE `memberdetails` 
SET street='New Street'
WHERE street='Old Street' AND city='Bedrock';

SELECT * from memberdetails;
+----+--------+--------------+---------+
| id | name   | street       | city    |
+----+--------+--------------+---------+
|  1 | Fred   | New Street   | Bedrock |
|  2 | Barney | New Street   | Bedrock |
|  3 | Slate  | Other Street | Bedrock |
+----+--------+--------------+---------+
3 rows in set (0.02 sec)

Works for me.
Show us your tables and data.

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
January 01, 2023 09:20AM
Re: Update with Logical Operator
January 03, 2023 05:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.