查询mysql - 结果出乎意料

时间:2017-07-17 12:28:56

标签: mysql

SELECT results.data_scrap AS data_badania,
  tests.data_test AS data_badania2,
  results.words_count_out_a AS liczba_slow,
  results.position AS pozycja
FROM results,
  tests,
  keywords
WHERE results.keyword=test
AND tests.id=1
ORDER BY results.position 

我得到了这个查询,我不知道为什么,但在我的结果中,一行重复了几次。

SELECT *
FROM results,
  tests,
  keywords
WHERE results.keyword=test
AND tests.id=1
ORDER BY results.position

结果为1.1.1.1.1.2.2.2.2.2.3.3.3.3.3而不是1.2.3

1 个答案:

答案 0 :(得分:2)

试试这个:

SELECT DISTINCT *
FROM results,
     tests,
     keywords
WHERE results.keyword=test
AND tests.id=1
ORDER BY results.position

或者,试试这个:

SELECT *
FROM results,
     tests,
     keywords
WHERE results.keyword=test
AND tests.id=1
GROUP BY results.position