I have three tables:
tbl_customers
tbl_users
tbl_reviews
I have an application where, customer submit reviews for users. What I want to be able to do is not have multiple reviews of the same user from the same customer. This is what I want to do.
SELECT
*
FROM
tbl_customers
WHERE
tbl_customer.CustomerID != tbl_review.CustomerID
AND tbl_user.UserID != tbl_reviews.UserID
- CustomerID is p_id for tbl_customer
- UserID is p_id for tbl_users.
- Foreign key relationship for both of them in tbl_review.
Thanks in advance.
If more information is needed please let me know.
Put a unique constraint on your tbl_reviews table which uses both columns. This will disallow multiple entries altogether which will allow you to do a simple join. You will just have to add validation for when the entry is added so it doesn’t error out when a user tries to enter more than one review for the same person.