Here is my DB structure:
CREATE TABLE `item` (
`item_id` int(11) NOT NULL auto_increment,
`user_id` int(20) NOT NULL,
`list_name` varchar(30) collate latin1_general_ci NOT NULL,
`date` date NOT NULL,
`store` varchar(30) collate latin1_general_ci NOT NULL,
`item` varchar(30) collate latin1_general_ci NOT NULL,
`itemprice` decimal(10,2) unsigned NOT NULL,
`itemnumber` tinyint(20) NOT NULL,
`itemtotalprice` decimal(10,2) NOT NULL,
PRIMARY KEY (`item_id`)
);
CREATE TABLE `lists` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(32) collate latin1_general_ci NOT NULL,
`dt` date NOT NULL,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ;
The way the site is structured you have to create a list before an item, then you add / edit / delete items in that list. When each item is created I store the list_name in the item table.
The question is if a user wants to delete a complete list how do I delete the corresponding items associated with that list? I'm guess when I query to delete the list I should do a separate query to delete all items where list_name = the list being deleted and user_id = the currently logged in user? Is that the most efficient way of doing it?