12

So I have a table and I want to create another table using "CREATE VIEW" from sql. I need to make a copy of the table that I am working with so I can use it 2x. My sql query would have to be like this:

SELECT A.time AS Start, B.time AS Stop
FROM time A, time B
WHERE A.id+1=B.id
AND A.bool=1
AND B.bool=0

my initial table is:

    String sql="create table "+TABLE+" ( "+C_ID+" INTEGER PRIMARY KEY AUTOINCREMENT, "
+C_TIME+" TEXT, "+C_BOOL+" NUMERIC)";

so anyone has any ideea where (in my code) I can create the view and how do I query it in android?

I can provide code if needed

Thank you :)

1 Answer 1

19

Based on this, you would create the view with the following statement:

CREATE VIEW view_name AS 
    SELECT A.time AS Start, B.time AS Stop
    FROM time A, time B
    WHERE A.id+1=B.id
        AND A.bool=1
        AND B.bool=0

You can create it right after you create the "base" table.

You can query it just like you would query any other table.

Sign up to request clarification or add additional context in comments.

5 Comments

I know it sounds stupid but I have a question: does sql know that A.time and B.time are rows? if not, how do I do that. (sorry, but i am pretty new with sql)
sqlite knows that A.Time and B.time are columns. Just to be clear, your time table has a column time?
my 'time' table has a column named 'times'
a column named times or time?
i think I need to change the name... it is confusing. the column is with s

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.