K
K
KKOOLL2020-10-20 03:44:14
SQL
KKOOLL, 2020-10-20 03:44:14

Compose sql query?

5f8e32b84b2de482864375.jpeg
it is necessary to display fields1, fields2 from table1, but not the code is displayed, but names from table2 (field1 and field2 are not equal)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-10-20
@KKOOLL

Use aliases:

create table Table1 (Code int, Field1 int, Field2 int);
create table Table2 (Code int, names varchar(255));
insert into Table1 values (1, 1, 2);
insert into Table1 values (2, 2, 1);
insert into Table2 values (1, "names1");
insert into Table2 values (2, "names2");

select t2a.names, t2b.names from Table1 t1, Table2 t2a, Table2 t2b
where t1.Field1 = t2a.Code and t1.Field2 = t2b.Code;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question