Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
python mysql.connector selecting rows with current date in a JOIN clause

I have the following piece of code which joins two tables and prints in a 2D list

print("Resident:\tRoom:\t\tLast check-in:")
print(' ')
join = "SELECT users.name, users.room, attendance.clock_in FROM users JOIN attendance ON users.id = attendance.user_id"
cursor.execute(join)
output = cursor.fetchall()
for x in range(len(output)):
    for y in range(len(output[x])):
        print(output[x][y], end = '\t | \t')
    print()

giving me the following output:

Resident:   Room:       Last check-in:
 
Name 1   |  W235     |  2020-05-10 17:57:17  |  
Name 2   |  E289     |  2020-05-10 17:58:08  |  
Name 1   |  W235     |  2020-05-10 18:18:22  |  
Name 2   |  E289     |  2020-05-10 18:18:36  |  
Name 1   |  W235     |  2020-05-10 18:18:41  |  
Name 1   |  W235     |  2020-05-16 16:01:38  |  
Name 2   |  E289     |  2020-05-16 16:07:31  |  
Name 2   |  E289     |  2020-05-16 17:13:50  |  
Name 2   |  E289     |  2020-05-16 17:13:53  |  
Name 2   |  E289     |  2020-05-16 17:13:58  |  
Name 1   |  W235     |  2020-06-29 22:41:23  |  
Name 2   |  E289     |  2020-07-15 16:27:13  |  
Name 1   |  W235     |  2020-07-15 16:27:23  | 

I need the output to be only those rows which checked-in today (in my output it's the last two rows). I tried manipulating with my "join" line, for example, changing it to:

join = "SELECT users.name, users.room, attendance.clock_in FROM users JOIN attendance ON users.id = attendance.user_id AND attendance.clock_in LIKE CURRENT_DATE"

but in all my attempts I get empty output instead of what I need:

Resident:   Room:       Last check-in:

So how do I type it correctly so that cursor selects only rows which include today's date?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

join = "SELECT users.name, users.room, attendance.clock_in FROM users JOIN attendance ON users.id = attendance.user_id WHERE attendance.clock_in >= CURDATE() AND attendance.clock_in < CURDATE() + INTERVAL 1 DAY"

over 4 years ago · Santiago Trujillo Report

0

join = "SELECT users.name, users.room, attendance.clock_in FROM users " \
       "JOIN attendance ON users.id = attendance.user_id " \
       "WHERE attendance.clock_in >= CURDATE() " \
       "AND attendance.clock_in < CURDATE() + INTERVAL 1 DAY"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!