Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table users (_id integer primary key, username text unique, first_name text, last_name text);
- create table tweets (_id integer primary key, content text, created_at integer, user_id integer, foreign key(user_id) references users(_id));
- create table connections (_id integer primary key, follower_id integer, followee_id integer, created_at integer, foreign key(follower_id) references users(_id), foreign key (followee_id) references users(_id));
- create table favorites (_id integer primary key, user_id integer, tweet_id integer, foreign key (user_id) references users(_id), foreign key (tweet_id) references tweets(_id));
- insert into users values (1, 'user1', 'Lorem', 'Ipsum');
- insert into users values (2, 'user2', 'Dolor', 'Sit');
- insert into users values (3, 'user3', 'Foo', 'Bar');
- insert into users values (4, 'user4', 'Qwerty', 'Trewq');
- insert into tweets values(10, '1 Tweet from user1', 1100, 1);
- insert into tweets values(11, '2 Tweet from user1', 1101, 1);
- insert into tweets values(12, '3 Tweet from user1', 1102, 1);
- insert into tweets values(13, '4 Tweet from user1', 1103, 1);
- insert into tweets values(14, '1 Tweet from user2', 1103, 2);
- insert into tweets values(15, '2 Tweet from user2', 1103, 2);
- insert into tweets values(16, '1 Tweet from user3', 1103, 3);
- insert into tweets values(17, '2 Tweet from user3', 1103, 3);
- insert into tweets values(18, '1 Tweet from user4', 1107, 4);
- insert into favorites values(1, 2, 11);
- insert into favorites values(2, 3, 13);
- insert into favorites values(3, 4, 15);
- sqlite> select favorites._id, tweets._id as tweet_row_id, tweets.content from favorites join tweets on tweets.user_id=1 and tweets._id = favorites.tweet_id order by tweets._id desc limit 1;
- _id tweet_row_id content
- ---------- ------------ ------------------
- 2 13 4 Tweet from user1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement