Sinclair Akoto
Sinclair Akoto

Reputation: 47

Multiple SQL Queries with python & flask

I have a SQLite3 table that collects data from a gym booking form; all the data goes into one table - Name, Email, Day, Exercise Class, Class Time.

If it is possible, I would like to find a way to get all from Name if Day, Exercise Class & Class Time are equal to a selected value.

I am using Flask so once I can do this the data would then be used to generate a new HTML page (which would be the registration checklist page for the gym tutor).

I am pretty sure this is incorrect, but this is the general idea of what I would like to achieve..

db.execute("SELECT * FROM GymTable WHERE (Day == "Monday", Ex_Class == "BoxFit", Ex_Time == "0745-0845"))

Upvotes: 1

Views: 1040

Answers (3)

Gabe
Gabe

Reputation: 995

To better illustrate:

db.execute( "
    SELECT name 
    FROM   gymtable 
    WHERE  day = 'Monday' 
        AND ex_class = 'BoxFit' 
        AND ex_time = '0745-0845' 
");

Upvotes: 1

DinoCoderSaurus
DinoCoderSaurus

Reputation: 6520

You may find these two tutorials on the SQL WHERE clause and SQL AND, OR, NOT Operators helpful. Notice first that the equal operator is = instead of ==. This query needs AND between column filters. The WHERE clause should not be enclosed in (). You may find the python sqlite3 doc useful as well.

Upvotes: 1

Kartik Narang
Kartik Narang

Reputation: 201

the correct query in this case would be:

db.execute("SELECT * FROM GymTable WHERE Day = 'Monday' and Ex_Class = 'BoxFit' and Ex_Time = '0745-0845'")

Upvotes: 1

Related Questions