I need some help writing a SQL statement. I have two tables in a SQLite database:
CREATE TABLE users (
user_id INTEGER PRIMARY KEY,
item_id INTEGER
);
CREATE TABLE items (
item_id INTEGER PRIMARY KEY,
ref_count INTEGER
);
I'm seeking a SQLite statement that will be like the following pseudocode:
for each row in items
items[ row ].ref_count = SELECT COUNT(users.item_id)
FROM users
WHERE users.item_id=row;