First off, apologies, wasn't replying directly to you -- confusing mess Hashnode is with TWO text entry boxes on every page; still adjusting. I'm used to just scrolling to the bottom and entering a reply.
But really I'm not sure I understood the OP's question or what you were doing with that massively complex create. Either I completely misunderstood what was being asked, or you guys are MASSIVELY overthinking this.
I think we need more clarification from Aqueel Aboobacker on just what it is he's doing with that select. Is that to select results from a query, or to store that value in the table.
Either way I'd be handling 0 as a special case in the QUERY, not the table.
If it's to query values (php example)
$baseQuery = '
SELECT *
FROM whatever
';
if ($_POST['routes'] == 0) $stmt = $db->prepare($baseQuery);
else {
$stmt = $db->prepare($baseQuery . '
WHERE routes = :routes
OR routes = 0
');
$stmt->bindParam(':routes', $_POST['routes']);
}
$stmt->execute();
Then you just store the zero. "OR" being the magic part of the solution. Then you don't have to screw around with the table structure at all. Just treat index 0 as all.
well add an extra mapping table :) n:m :)
CREATE TABLE user_selected_route (user_id INT(11), route_id INT(11), PRIMARY KEY (user_id, route_id), CONSTRAINT fk_my_user_key FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_my_route_id FOREIGN KEY (route_id) REFERENCES route(id) ON DELETE CASCADE ON UPDATE CASCADE);something along the line of this :)
so if the user should have to be able to save multiple of these we would need another table between it.