I have this sql string:
Dim sqlQuery As String = "SELECT TOP 1 ID, FName, FoodGroup, Calories, Protein, Carbohydrates, Fat, category.ID" &
" FROM food where Protein<='" & txtProt.Text.ToString() & "' and FoodGroup = 4 " & "and category.ID = 1 " & "JOIN foodCategory ON food.ID = foodCategory.Food_ID" & "JOIN category ON foodCategory.Category_ID = category.ID " & "ORDER BY NEWID() "
What i want to do is this: I want to type the value “FName” from table “food” to an textBox where the “ID” field of table “category” is 1.
I have 3 tables. The first is table food, the second one is table category and the third one is foodCategory.
The table foodCategory has the ID’s from the first 2 tables to a one-to-many relationship.
I get the following error : Incorrect syntax near JOIN.
What do i do wrong?
your query is incorrect, the JOINs have to be set within the FROM clause, not in the WHERE clause.