SELECT TotalItems.Total_Items
,TotalItems.No_Items_Present
,ItemsTable.No_Of_Items_Ret
FROM TotalItems
INNER JOIN ItemsTable ON
ItemsTable.Item_Name= '" + DropItemName.SelectedValue + "'"
this is my SQL query what I want is to retrieve two column values corresponding to the item I enter in my dropdown list from one table and the no_of_items_ret
from a开发者_StackOverflownother table satisfying the condition of the dropdownlist
I'm getting all the values corresponding to any item I enter what should i do?
I think you're confusing the WHERE clause in SQL with the ON clause used to join tables.
Put your "filter condition" in a WHERE clause:
WHERE ItemsTable.Item_Name= '" + DropItemName.SelectedValue + "'"
The ON clause should contain the condition used to join the tables. For example:
TotalItems
INNER JOIN ItemsTable ON TotalItems.SOME_COLUMN = ItemsTable.SOME_OTHER_COLUMN
ItemsTable.Item_Name= '" + DropItemName.SelectedValue + "'"
looks like it should be after the WHERE clause.
SELECT TotalItems.Total_Items
,TotalItems.No_Items_Present
,ItemsTable.No_Of_Items_Ret
FROM TotalItems
INNER JOIN ItemsTable ON TotalItems.[reference] = ItemsTable.[reference]
WHERE ItemsTable.Item_Name= '" + DropItemName.SelectedValue + "'"
reference should be the field that ties the tables together.
Your join defines no relationship between TotalItems and ItemsTable, so all rows in the first table will be joined to all rows in the second.
If TotalItems and ItemsTable are related, you could do this:
Select
TotalItems.Total_Items,
TotalItems.No_Items_Present,
ItemsTable.No_Of_Items_Ret
from TotalItems
INNER JOIN ItemsTable
ON ItemsTable.ItemID = TotalItems.ItemID
WHERE ItemsTable.Item_Name= '" + DropItemName.SelectedValue + "'"
精彩评论