create restrictions on one based on a date (mysql) [closed]

0

I would like someone to help me, I have three tables called "users", another called "activities" and the last one called control_activities, activities and users have a PK id, and in control activities what I intend is control which users are targeted and which activity is targeted by saving the date in which they are targeted. But what I do not know how to do is to control that a user can only sign up for an activity per day ... could someone help me?

    
asked by Adria Tomas Altes 18.02.2017 в 19:32
source

1 answer

0

You can validate it by obtaining the number of records that are associated with a person's id and to date if the amount is greater than 1 it is already associated with an activity:

    SELECT COUNT(*)
    FROM   CONTROL_ACTIVIDADES
    WHERE  ID_PERSONA = 'ALGUN_ID_DE_PERSONA'
    AND    DATE_FORMAT(CURDATE(), '%d/%m/%Y') = DATE_FORMAT(FECHA, '%d/%m/%Y')

PS: if you upload an image of your ER model, I can help you with your query.

    
answered by 18.02.2017 / 19:59
source