如何从mysql中的内连接查询中删除重复的行

时间:2013-11-06 22:47:26

标签: mysql html5

我有四张桌子

CREATE TABLE IF NOT EXISTS Englishword (WordId int NOT NULL,WordName varchar(100) NOT NULL,PRIMARY KEY (WordId))

CREATE TABLE IF NOT EXISTS MeaningInAmharicforEnglish (MeaningidA int(11) NOT NULL,WordIdA int NOT NULL,MeaningNameA varchar(50) NOT NULL,WordclassA varchar (50) NOT NULL,PRIMARY KEY (MeaningidA),FOREIGN KEY (WordIdA) REFERENCES Englishword(WordId) ON UPDATE CASCADE ON DELETE CASCADE) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci

CREATE TABLE IF NOT EXISTS MeaningInTigrgnaforEnglish (MeaningidT int(11) NOT NULL,WordIdT int NOT NULL,MeaningNameT varchar(50) NOT NULL,WordclassT varchar (50) NOT NULL,PRIMARY KEY (MeaningidT),FOREIGN KEY (WordIdT) REFERENCES Englishword(WordId) ON UPDATE CASCADE ON DELETE CASCADE) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci

CREATE TABLE IF NOT EXISTS MeaningInEnglishforEnglish (MeaningidE int(11) NOT NULL,WordIdE int NOT NULL,MeaningNameE varchar(100) NOT NULL,WordclassE varchar (50) NOT NULL,PRIMARY KEY (MeaningidE),FOREIGN KEY (WordIdE) REFERENCES Englishword(WordId) ON UPDATE CASCADE ON DELETE CASCADE)

我有一个数据 Englishword

  

1去

我有一个数据 MeaningInEnglishforEnglish

  

1 1你好动词
  2 1你好名词

我有一个数据 MeaningInAmharicforEnglish

  

1 1ራቀ动词
  2 1ራቀ名词

我有一个数据 MeaningInTigrgnaforEnglish

  

1 1ሄደ动词
  2 1ሄደ名词

我使用了以下查询

SELECT  WordId,
WordName,WordclassE,MeaningidE,MeaningNameE,WordclassA,MeaningidA,MeaningNameA,WordclassT,MeaningidT,MeaningNameT

FROM Englishword AS E, MeaningInEnglishforEnglish AS EM, MeaningInAmharicforEnglish AS AE, MeaningInTigrgnaforEnglish AS TE

WHERE (E.WordId = EM.WordIdE)
AND (E.WordId = AE.WordIdA)
AND (E.WordId = TE.WordIdT)

这给了我以下结果:

 WordId     WordName  WordclassE  MeaningidE  MeaningNameE  WordclassA  MeaningidA   
 1              go      verb       1            hello         verb     1   
 1              go      verb      1             hello         verb         1 
 1              go      verb      1             hello         verb         1
 1              go      verb      1             hello         verb         1
 1              go      verb      2             hello         verb         2 
 1              go      verb      2             hello         verb          2 
 1              go      verb      2             hello         verb          2 
 1              go      verb      2             hello         verb          2 

和其他领域一样,根据他们在表中的价值重复,我怎么想成为这样的结果

WordId    WordName MeaningidE wordclass MeaningNameE WordclassA MeaningidA MeaningNameA 
1          go         1         verb       hello      verb       1             ራቀ 
Null       Null       2         verb       hello      verb       2             ራቀ

和同样是为了休息领域

h如何通过删除重复的行来编写显示为所需查询的查询?

1 个答案:

答案 0 :(得分:0)

如果你可以请格式化答案,那就太好了。从目前的方式来看,并不是很多人都能理解的。
我想你的解决方案是使用GROUP BY column_name来获得重复的字段。
尽量在下次尽可能清楚地格式化您的问题。