There are 2 tables:

The first table is 2 fields: id_param , name_param . Rows: 1 => param_1 , 2 => param_2 Second table 2 fields: id_param , value_param . Lines: 1 => 256, 2 => 586

How to build a query to the database to immediately get:

 param_1 => 256 param_2 => 586 

Is it possible to do this in one request?

  • so it is impossible to do, and why ?? - nosf
  • Why? .... Good question. By my stupidity, I once used the EAV model in a project - now the question is - how can I filter several entities with one query, according to certain attributes (without using php cycles)? - DenisRD
  • Compare the results of the query with your own: SQL> SELECT trunc (date1-date2) days, 2 to_char (trunc (sysdate) + (date1 - date2), 3 'HH24 "Hours" MI "Minutes" SS "Seconds"') time 4 FROM dates; DAYS TIME ---------- ------------------------------ 1 00 Hours 00 Minutes 00 Seconds 0 01 Hours 00 Minutes 00 Seconds 0 00 Hours 01 Minutes 00 Seconds Learn - jmu
  • Unfortunately, I do not have a secretary who would make my texts beautifully. Knowledgeable people even without this will understand what I meant. - DenisRD
  • > learn to work secretary? - DenisRD 1:01 pm

2 answers 2

 select t1.name_param, t2.param_value from первая_таблица as t1, вторая_таблица as t2 where t1.id_param=t2.id_param 
  • Similarly. I know what join is used for. But he will give me 2 results. And you need 1 - DenisRD
  • If you understand correctly, then select (select t1.name_param, t2.param_value from first_table as t1, second_table as t2 where t1.id_param = t2.id_param and rownum = 1 order by t1.name_param), (select t1.name_param, t2 .param_value from first_table as t1, second_table as t2 where t1.id_param = t2.id_param and rownum = 2 order by t1.name_param) from dual If you have more than two values, you can make a function - cadmy
  • Yes, values ​​are greater than 2. The number of values ​​is unknown in advance ... But I have never come across functions, I will study them. Can someone meet the examples of filtering entities by attributes in the EAV model? Magento, for example, uses this model, but it's hard to understand something there ... - DenisRD

Perhaps for this you need to make a query from two tables, or I highly recommend reading the join instruction to read the link.

in the end you get:

 select tbl1.name_param, tbl2.value_param from tbl1 join tbl2 on (id_param=tbl1.id_param) 

or

 select tbl1.name_param, tbl2.value_param from tbl1, tbl2 where tbl1.id_param = tbl2.id_param 
  • In this case, I will get 2 lines of this type: 1) name_param => param_1 value_param => 256 2) name_param => param_2 value_param => 586 Ie arrays in which the keys are the column headers of the tables, the values ​​are the term values ​​in the tables. I need an array in which the keys and values ​​correspond to the values ​​of the strings - DenisRD
  • Well, damn, if you need only one line, add: where param_id = 1 - Alex Kapustin
  • and you, understand the condition completely and then you will understand everything - nosf