I have a favorite table containing some fields like login_id,driver_id(One login_id may have many driver_id) . Then I am using bulk update , not having any check the driver_id is exists in table .
Input data will be set of driver ids , I need to skip the insertion of driver id if the same id already be there for relevant login_id . So the new ids will be inserted and others are not
What can I do with mysql , what are all the settings needed in table .
Please advise me
You can prevent duplicate values in a field in an Access table by creating a unique index.
If you want the query to return only unique rows, use the keyword DISTINCT after SELECT . DISTINCT can be used to fetch unique rows from one or more columns. You need to list the columns after the DISTINCT keyword.
You can use "INSERT IGNORE INTO".it's return updated row count.
INSERT IGNORE INTO favorite(login_id,driver_id) VALUES (login_id,driver_id) (login_id,driver_id).....
create a unique key with login_id and driver_id in mysql.
When you try to insert an existing record based on those keys, an error will be thrown. You can then trap this error and proceed as normal.
CREATE UNIQUE INDEX unique
ON tbl_name (login_id, driver_id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With