I'm starting in SQL and I'm having trouble making a query
with multiple rows returned. I'm creating a generic twitter clone.
Goal: Return users who are followed by people who logged in user follows and displays as people he or she may know, excluding himself and the people he already follows.
Tables
CREATE TABLE 'usuarios' (
'id' int(11) NOT NULL,
'usuario' varchar(60) NOT NULL,
'email' varchar(100) NOT NULL,
'foto' varchar(80) DEFAULT 'imagens/semfoto.png'
);
CREATE TABLE 'usuarios_seguidores' (
'id_usuario_seguidor' int(11) NOT NULL,
'id_usuario' int(11) NOT NULL,
'seguindo_id_usuario' int(11) NOT NULL,
'data_registro' datetime DEFAULT CURRENT_TIMESTAMP
);
This command below returns the people the logged-in user ( $id_usuario
) follows, however that would be only the first part of the return.
SELECT seguindo_id_usuario
FROM usuarios AS u
LEFT JOIN usuarios_seguidores AS us
ON (us.id_usuario = u.id)
WHERE id_usuario = $id_usuario;
Thanks for the help.