How can I query 2 SqlLite tables with a join and multiple where statements

  Kiến thức lập trình

I’m trying to write an SQLite query that would return a row, that would execute the following statement:

Select all messages, where the Action.action is receive, and Action.name is john. Also if message_id is not null, show Action.name as sender_name where message_id is the same

Output Results

message name sender_name
Hello World! john dave
Anonymous Message john <null>

Action Table

id message_id action name
1 1 send dave
2 1 receive john
3 <null> send dave
4 2 receive john

Message Table

id message
1 Hello World!
2 Anonymous Message

I’m also using Sqlalchemy so if there is an even easier way to achieve this, please let me know.

Could anyone shed any light on how to achieve this please?

LEAVE A COMMENT