mercredi 20 juillet 2016

Select data from tables in sql

I have these tables and I want to select my messages and my friends' messages.

CREATE TABLE Friends(
    userId int,
    friendId int,
    CONSTRAINT PRIMARY KEY(userId, friendId)
);

CREATE TABLE Message (
    id       int auto_increment PRIMARY KEY,
    date     datetime,
    text     text,
    urlPhoto varchar(255),
    type     varchar(255),
    idAuthor int,
    idTarget int
);

Assuming my id is 1, it's easy to select my friends' ids:

SELECT friendId FROM Friends WHERE userid=1;

but I can't use that id to select the messages.

Aucun commentaire:

Enregistrer un commentaire