I have a simple many-to-many three-table set-up: - CREATE TABLE `people` (
-
`id` int(10) unsigned NOT NULL auto_increment,
-
`salutation` varchar(15) default NULL,
-
`forename` varchar(60) NOT NULL default '',
-
`middle_initial` varchar(5) NOT NULL default '',
-
`surname` varchar(60) NOT NULL default '',
-
`suffix` varchar(10) default NULL,
-
`is_tenant` tinyint(1) NOT NULL default '0',
-
PRIMARY KEY (`id`),
-
KEY `is_tenant` (`is_tenant`),
-
KEY `fullname` (`surname`,`forename`)
-
)
-
-
CREATE TABLE `phones` (
-
`id` int(10) unsigned NOT NULL auto_increment,
-
`phone_label` varchar(127) NOT NULL default '',
-
`notes` varchar(127) NOT NULL default '',
-
`number` varchar(255) NOT NULL default '',
-
PRIMARY KEY (`id`)
-
)
-
-
CREATE TABLE `person_phones` (
-
`person_id` int(10) unsigned NOT NULL,
-
`phone_id` int(10) unsigned NOT NULL,
-
PRIMARY KEY (`person_id`,`phone_id`),
-
KEY `phone_id` (`phone_id`)
-
)
mapping a person to a number of phones (phones can also be mapped to organisations - another table - which explains why I'm not using a simple one-to-many).
Starting from a value of people.id (which corresponds to person_phones.person_id) I want to be able to delete the link in person_phones and the corresponding entry in phones. I realise that I have to do this in reverse order using some sort of join or sub-select to delete the phones first, and then the link, but for the life of me I can't get the syntax right.
Anyone have any ideas?
2 1103
Sorry - managed to fix problem myself - was making it over complicated: - delete from phones where id in (select phone_id from person_phones where person_id = 5396);
Again, apologies.
Atli 5,058
Expert 4TB
Hi. Welcome to The Scripts!
I'm glad you were able to solve your problem.
Don't hesitate to post again if you have any questions or problems we can help with.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sebastian |
last post by:
Hi
I got a little problem with deleting from my database, i'm making a
simple newsscript. I get a Parse error: syntax error, unexpected
T_ELSE on line 24, I have written the error as a comment...
|
by: Wilfredo Sanchez |
last post by:
The docs for imaplib are pretty scant, and i guess the library is
meant for people who already know IMAP well and want low-level access to
the protocol, as opposed to someone who wants "get me the...
|
by: Savas Ates |
last post by:
i cant delete data from excell which i use as a database with asp .. i
encounter an error report about isam. how can i delete data from excell help
meee!
|
by: Dariusz Tomoń |
last post by:
Hi
How could I perform the task of deleting or renaming file on the server
where I have ISS via ASP page.
best ragards
Derek
|
by: Mark |
last post by:
Not sure this is the right place for this questions, but here goes:
I get an error message when deleting an table from a Access database.
The code is as follows and the error message is after...
|
by: Rick |
last post by:
Hi,
Does deleting an object more than one times incur undefined behavior? I
think it doesn't but just making sure... thanks
Rick
|
by: Microsoft News Group |
last post by:
I am setting up a customer portal. I am setting up users, and then deleting
them. But if I set up a user with the same name I deleted. Then I get this
error.
The user 'Flynn' is already in...
|
by: Christian Bruckhoff |
last post by:
Hi.
I got a problem with deleting items of a vector. I did it like this:
void THIS::bashDelPerson() {
cout << "Bitte Suchstring eingeben: ";
char search;
cin >search;...
|
by: vikram.lakhotia |
last post by:
Hi
Have you tried deleting a directory in Asp.Net. Here is an article
discussing the problem deleting a Directory in Asp.Net
http://www.vikramlakhotia.com/Deleting_Directory_in_ASPnet_20.aspx...
|
by: gauravgmbhr |
last post by:
hi friends
I have been doing testing on an existing project
The tables in postgresQl Db has some trigger function using keyword 'DELETING'
IF DELETING THEN
SOME SELECT STATEMENT...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |