*Parent table* : Vehicle
CREATE TABLE `vehicle` (
`vehicle_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`version_number` INT(10) UNSIGNED NULL DEFAULT '0',
`vehicle_no` VARCHAR(64) NOT NULL COLLATE 'utf8_bin',
`vehicle_reg_no` VARCHAR(64) NOT NULL COLLATE 'utf8_bin',
`vehicle_name` VARCHAR(64) NOT NULL COLLATE 'utf8_bin',
`total_seat` INT(15) NOT NULL,
`route_id` INT(10) UNSIGNED NOT NULL,
`available_seat` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`vehicle_id`)
)
Child Table : allocate_vehicle
CREATE TABLE `allocate_driver` (
`allocate_driver_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`version_number` INT(10) UNSIGNED NULL DEFAULT '0',
`vehicle_id` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`allocate_driver_id`),
INDEX `fk_vehicle_idx` (`vehicle_id`),
CONSTRAINT `fk_vehicle_idx` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicle` (`vehicle_id`) ON UPDATE NO ACTION ON DELETE NO ACTION,
)
so i given this query : select veh.* from vehicle as veh JOIN allocate_driver as allDr on veh.vehicle_id!=allDr.vehicle_id
but not work properly… before insert i want the list of vehicle after assign the per vehicle it should not display in list.. any one can tell me.. thanks in Advance 🙂
If I understand this correctly, you want to find the vehicles that is not allocated to
anydriver. Your query will find the vehicles that is not allocated tosomedriver (and will return them once for each of those drivers).Then this query should give you what you want: