I have the following data sets:

A list of users.

Tom, Lisa, Karen

These users can manage any shop (one or more):

Barba, Rentraum, Kisabran, Tespot and Lowvel

These shops can provide any services/products:

Yoga, Coffee, Mechanics, Gym

These services can receive a complaint, which can only BE for ONE service at a given SHOP!

Complaint 1 -> Yoga at Kisa
Complaint 2 -> Yoga at Tesport
Complaint 2 -> Cofee at Barba

Now, I want at any time to PASS the user_id (Tom, Lisa, Karen) to a query, and get all COMPLAINTS eligible to that user.

  • It seems you have two tables: one for links between managers and shops and the second one is compliant table which contains shop_id and service_id. You just need to create corresponding indexes to join them on shop_id and use filter on user_id. – Nikita Feb 8 at 16:13
  • 1
    Please replace verbal explaination about what tables and data you have, post all tables DDLs (including complaints table) as CREATE TABLE and data as INSERT INTO. And show desired output for this data. – Akina Feb 8 at 17:48
  • These users can manage any shop (one or more): What is the relation? Does more than one user may manage the same shop? – Akina Feb 8 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.