列的我有全部具有相同的列,但不同數據的兩個表。他們代表兩個不同的日子。這些表格是D1Table和D2Table。這些列是author1,author2,author3,author4,author5,position1 - position5,title和biography- biography5。在查詢中,我嘗試獲取與用戶輸入文本框中的文本相匹配的列(以便他們可以在兩天內進行搜索)。SQL查詢兩個表很多
我至今工作於第一個表不錯,但我真的想同時搜索第一和第二個表,我只是不知道如何,我曾嘗試使用和加入工會,但我沒有很幸運,我只是得到錯誤,顯然我做錯了什麼。此外,我現在用的查詢是很長的,你可以看到,我肯定必須有一個更好的方式來做到這一點:
txt = "SELECT * from D1Table WHERE Synopsis LIKE '%" + txtBText +
"%' OR Author1 LIKE '%" + txtBText + "%' OR Author2 LIKE '%" + txtBText +
"%' OR Author3 LIKE '%" + txtBText + "%' OR Author4 LIKE '%" + txtBText +
"%' OR Author5 LIKE '%" + txtBText + "%' OR Biography1 LIKE '%" + txtBText +
"%' OR Biography2 LIKE '%" + txtBText + "%' OR Biography3 LIKE '%" + txtBText +
"%' OR Biography4 LIKE '%" + txtBText + "%' OR Biography5 LIKE '%" + txtBText +
"%' OR Title LIKE '%" + txtBText + "%' OR Position1 LIKE '%" + txtBText +
"%'OR Position2 LIKE '%" + txtBText + "%' OR Position3 LIKE '%" + txtBText +
"%' OR Position4 LIKE '%" + txtBText + "%' OR Position5 LIKE '%" + txtBText + "%' ";
現在我知道這是很可怕的,正如你也許能告訴我垃圾與SQL查詢(我剛開始學習它們)。我一直在尋找整個互聯網一段時間,試圖學習語法,但這是我所知道的,所以我認爲這可能是我要求幫助的時候。如果任何人都可以給我一些指導,將不勝感激。
這看起來很有趣,我會考慮這樣做,感謝您的鏈接。 – OverHere 2012-04-29 17:08:27