内连接有2个主键

时间:2014-04-05 01:31:10

标签: mysql sql

以id含义结尾是主键但是当表4使用2个主键时我该怎么办? 在1个选择语句中显示content2,content3和content1

CREATE TABLE table1
(table1ID   CHAR(4),
 content1   VARCHAR,

CREATE TABLE table2
(table2ID   CHAR(4),
 content2   VARCHAR,

CREATE TABLE tablet3
(table3ID   CHAR(4),
 content3   VARCHAR,
 table2ID    CHAR(4),

CREATE TABLE tablet4
(table1ID   CHAR(4),
 table3ID   CHAR(4),

1 个答案:

答案 0 :(得分:0)

如果我理解正确:

 SELECT content1
       ,content2
       ,content3
  FROM           table1 t1
      INNER JOIN table4 t4 ON t1.table1ID = t4.table1ID
      INNER JOIN table3 t3 ON t4.table3ID = t3.table3ID
      INNER JOIN table2 t2 ON t3.table2ID = t2.table2ID