Answer the question
In order to leave comments, you need to log in
What is the best way to get a sample from MySQL?
Hello!
Help compose a query to create a Tabular Data Fetch View:
Source tables:
Request (Table of Requests) - r_id, u_id
ROLink (Table of Option-Request Links) - r_id, op_id
ROptions (Table of Request Options) - op_id, name, container
UOLink (Table of Links option-user) - u_id, op_id
UOptions (Table of user options) - op_id, name, container
The output should be a table like:
r_id, ROptions.container where name = "city", ROptions.container where name = "branch", UOptions where name = "full name"
Answer the question
In order to leave comments, you need to log in
SELECT Request.r_id, ROpt_City.container, ROpt_Filial.container, UOptions.container
FROM Request
LEFT JOIN ROLink ON (ROLink.r_id = Request.r_id)
LEFT JOIN ROptions AS ROpt_City ON (ROLink.op_id = ROpt_City.op_id AND ROpt_City.name = 'город')
LEFT JOIN ROptions AS ROpt_Filial ON (ROLink.op_id = ROpt_Filial.op_id AND ROpt_City.name = 'филиал')
LEFT JOIN UOLink ON (ROpt_City.op_id = OULink.op_id OR ROpt_Filial.op_id = OULink.op_id)
LEFT JOIN UOptions ON (UOLink.op_id = UOptions.op_id AND UOptions.name = 'ФИО')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question