Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. create table users (_id integer primary key, username text unique, first_name text, last_name text);
  2. create table tweets (_id integer primary key, content text, created_at integer, user_id integer, foreign key(user_id) references users(_id));
  3. 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));
  4. 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));
  5.  
  6. insert into users values (1, 'user1', 'Lorem', 'Ipsum');
  7. insert into users values (2, 'user2', 'Dolor', 'Sit');
  8. insert into users values (3, 'user3', 'Foo', 'Bar');
  9. insert into users values (4, 'user4', 'Qwerty', 'Trewq');
  10.  
  11. insert into tweets values(10, '1 Tweet from user1', 1100, 1);
  12. insert into tweets values(11, '2 Tweet from user1', 1101, 1);
  13. insert into tweets values(12, '3 Tweet from user1', 1102, 1);
  14. insert into tweets values(13, '4 Tweet from user1', 1103, 1);
  15.  
  16. insert into tweets values(14, '1 Tweet from user2', 1103, 2);
  17. insert into tweets values(15, '2 Tweet from user2', 1103, 2);
  18.  
  19. insert into tweets values(16, '1 Tweet from user3', 1103, 3);
  20. insert into tweets values(17, '2 Tweet from user3', 1103, 3);
  21.  
  22. insert into tweets values(18, '1 Tweet from user4', 1107, 4);
  23.  
  24. insert into favorites values(1, 2, 11);
  25. insert into favorites values(2, 3, 13);
  26. insert into favorites values(3, 4, 15);
  27.  
  28. 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;
  29. _id tweet_row_id content
  30. ---------- ------------ ------------------
  31. 2 13 4 Tweet from user1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement