开发者

Creating dynamic queries for SQLite3

I have 开发者_JAVA百科2 tables in a DB.

Table2 has values that would be needed for Table1

Example

Table1 has the following fields

Name FoodColor FoodSmell FoodCookingStyle

As we all know certain foods can be cooked in a variety of ways (while producing the same results). One approach is to create a new row for each variation.

Table2 would have data for FoodCookingStyle like FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3

So the result is I want to create a Query that uses the results from Table2 to produce a SQL Query that would look like

SELECT * FROM TABLE1 WHERE FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3

(only difference is I want to query table2 instead of typing out the expression).

Type of DB being used is SQLite3.

Thank you


To clarify what I meant. I need the output for table2 to be the input for table1


The question is a bit confusing. Is it subqueries you're looking for ? Subquery syntax is along the lines of SELECT * FROM Table1 WHERE FoodCookingStyle IN ( SELECT FoodCookingStyle FROM Table2 WHERE FoodCookingStyle=1 OR FoodCookingStyle=2 OR FoodCookingStyle=3 )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜