G
G
Goshujin2022-01-03 07:31:13
Python
Goshujin, 2022-01-03 07:31:13

How to output data from one table for each row to another?

The table is arranged as follows:
Id ║ UserId ║ UserName ║ UserDateAdded
the values ​​​​from it are displayed in this way:

description = '\n'.join(' ║ '.join(f'{val}' for val in row) 
            for row in cursor.execute("SELECT * FROM Table"))

At the end you need to do
+ cursor.execute(f"SELECT COUNT(UserId1) FROM Table2 WHERE UserId1 = {UserId}")

The question is how to get the UserId and add it to all results.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2022-01-03
@tumbler

select user_id, count(*) from table1 inner join table2 using (user_id) group by user_id

More or less like this. References: JOIN, GROUP BY

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question