简体   繁体   中英

Join different columns from different tables (SQL)

I have 8 different tables and I would like to select only specific columns in one query. If I use this query I have wrong results :(

SELECT a.entity_id id
     , a.field_imie_value imie
     , c.field_nazwisko_value nazwisko
     , d.field_preferencja_1_value preferencja1
     , e.field_preferencja_2_value preferencja2
     , f.field_preferencja_3_value preferencja3
     , g.field_nr_niu_value nr_niu
     , h.dystans odleglosc
     , i.field_sytuacja_value sytuacja   
  FROM field_data_field_imie a
  JOIN field_data_field_nazwisko c
     , field_data_field_preferencja_1 d
     , field_data_field_preferencja_2 e
     , field_data_field_preferencja_3 f
     , field_data_field_nr_niu g
     , field_data_field_adres h
     , field_data_field_sytuacja i
 WHERE a.entity_id = b.entity_id 
   AND a.entity_id=c.entity_id

使用联接表时,必须使用类似于以下内容的语法:

select A.field1 from table1 AS A inner join table2 as B on A.field1 = B.field1

syntax should be like this;

SELECT *  
FROM field_data_field_imie a
JOIN field_data_field_nazwisko c on (a.entity_id=c.entity_id)
JOIN table x on (x.column=a.entitiy_id)

or you shouldn't use join at all.

actually number of tables is the important thing not how many fields you want however this is the syntax for joining more table : elect A.field1 from table1 AS A inner join table2 as B on A.field1 = B.field1 inner join table3 AS C on table1.field1 = C.field1

and syntax for more joining is similar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM