-- to check duplicate CarRegistration
SELECT 
    `driverID`,
    COUNT(*) AS `count`,created_at
FROM 
    `CarRegistration`
GROUP BY 
    `driverID`
HAVING 
    COUNT(*) > 1;
--  


--  to delete duplicate
WITH CTE AS (
    SELECT 
        MIN(`id`) AS `min_id`
    FROM 
        `CarRegistration`
    GROUP BY 
        `driverID`
)
DELETE FROM 
    `CarRegistration`
WHERE 
    `id` NOT IN (SELECT `min_id` FROM CTE);

--  get for employee
SELECT
    d.`maritalStatus` AS NAME,
    COUNT(*) AS `count`
FROM
    `driver` d
WHERE
    d.`maritalStatus` IN('Maryam', 'Salma', 'Mena') AND DATE(d.created_at) = CURDATE()
GROUP BY
    d.`maritalStatus`
ORDER BY
    COUNT
DESC
    
    
    -- get driver without cars 

    SELECT
    d.id, d.phone
FROM
    `driver` d
WHERE
    d.id NOT IN (SELECT driverID FROM CarRegistration);


    -- car without drivers

    SELECT
   cr.created_at, cr.driverID
FROM
    `CarRegistration` cr
WHERE
    cr.driverID NOT IN (SELECT id FROM driver);



----- driver 
    SELECT phone,email,name_arabic,national_number FROM `driver`  WHERE national_number ='29209290106392'
ORDER BY `driver`.`created_at` DESC