Search code examples
pythonmysqlsyntaxpymysql

PyMySQL Syntax when using two tables


I have 2 mysql tables:

-Attendance:

att id      | child id
--------------------------
A0012       | C002
A0034       | C001
A0064       | C003
A0065       | C003
A0066       | C003

-Day Prices:

att id      | price  | date
--------------------------
A0012       | 30.00  | 2015-01-26
A0034       | 45.00  | 2015-01-26
A0064       | 62.50  | 2014-12-30
A0065       | 20.0   | 2015-01-02
A0066       | 90.0   | 2015-01-03

I am using pymysql to select the 'price' and 'data' columns from the 'Day Prices' table. However, I would only like such data that corresponds to 'child id' that is 'C003'. This is so that I should obtain only:

 price  | date
--------------------
 62.50  | 2014-12-30
 20.0   | 2015-01-02
 90.0   | 2015-01-03

This is my query:

"SELECT price, date FROM Day Prices WHERE att id FROM Attendance = att id FROM Day Prices WHERE child id = 'C003'"

This query doesn't work so any help coming up with a solution is much appreciated!


Solution

  • How about

    select d.price, d.date FROM `Day Prices` d
    join Attendance a 
    on a.att id = d.att id
    where a.child id = 'C003';