SQL Query - SELECT WHERE Table1.ID = Table2.ID AND Table2.Var = @Var
I am trying to create a SQL query for an ASP NET dropdown using two tables and a session variable.
I want to get all the values ββfrom table 1 that match the match IDs in table 2 where table 2 is filtered by an external variable.
As is clear, I don't know how to frame this question, here is a simplified example of what I am trying to do:
- My site has a session variable that contains the current color that the user "filters".
- The dropdown will display a list of cars matching that color using an SQL query.
For example, if the session variable was Blue, the dropdown would contain Punto because he can see that the color ID for Blue is 12 and Punto is the only car name that matches that color.
Associated image: http://i.imgur.com/fe9L12c.png
Since session variables can be assigned and called in custom ASP.NET requests, the session variable can be simply named, for example @ExternalVar (Colors.ID WHERE (Colors.Name = @ExternalVar))
Apologies, I had to say this as a quiz question; by giving a simplified example, I was the only way I could formulate my question.
source to share