Tell me - I have a sign in which there is a field "operation code", "code of debit account", "code of credit account". Is it possible to somehow make a request that, depending on the value of the field operation code, the values ​​selected by the account code from different tables? Or it can generally be solved in some other ways. If the operation code is 1, then the score is taken via Join from one table; if 2, then from another table

  • 2
    over left join glue both secondary tables and in the select list with ifnull or case resolve which of the values ​​to take - Mike
  • Two queries, one join with the table for operation number 1, the other join with the table for operation number 2 are combined into one query using the magic word UNION between these two queries. Provided that these requests give the same fields - Sergey
  • Thank you. The fields are the same. UNION did not use yet - I study. And what will be faster one request with CASE or a chain with UNION? - Artem Tikhonovich
  • You can not use case, but insert fields from join tables into a record in a specific order. In the receiving program, look at the opcode. If it is equal to 1, then the data should be taken from a column of 3, and if the code is 2, then from column 4. - Sergey
  • Also a good option - choose the maximum, and display only what you need. Thank. - Artem Tikhonovich

0