打擾一下,我沒有用英文提出一個明確的問題。php mysql查詢出所有的單詞,但不重複
我需要一些像這樣的mysql查詢:通過兩個表查詢所有項目名稱,UNION
,但不重複。
這裏是我的表結構:
表:cxt_20110105
item | ... many columns, but does not affect query, because I just need item.
art |
collectibles |
furniture |
books |
arts |
books |
... many lines...
表:cxt_20110106
item | ... many columns, the columns structure is as well as table: cxt_20110105.
art |
tickets |
cars |
furniture |
tickets |
cars |
... many lines...
所以
mysql_query(//how to write in here?)
while ($row = mysql_fetch_array($result))
{
//the result should be: art, collectibles, furniture, books, tickets, cars(every word, but not repeat) ;
}
感謝。
從[mysql文檔](http://dev.mysql.com/doc/refman/5.0/en/union.html):「UNION的默認行爲是重複的行從結果中刪除。可選的DISTINCT關鍵字除默認外沒有任何作用,因爲它還指定重複行刪除。「 – 2011-05-13 21:01:22
我更喜歡寫明確的查詢,以明確發生了什麼。默認值是好的,但看到這樣拼寫出來就會讓其他人更清楚。 – 2011-05-13 21:06:46
正確,DISTINCT沒有用。答案很簡單。我沒有很好地學習基礎知識。謝謝。 – cj333 2011-05-13 21:07:37