GithubHelp home page GithubHelp logo

princesah09 / 3-twitter-queries Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 15 KB

This repository contains SQL queries for interacting with a Twitter-like database schema. The queries perform various operations such as fetching user information, tweet statistics, and user timelines.

3-twitter-queries's Introduction

Assignment-3-Twitter-Queries

Note: All data are stored inside the repo file (Twitter_Querry.sql)

Answers of Assignment

1. Fetch all users name from database.

 select
    user_name
from
    users;

2. Fetch all tweets of user by user id most recent tweets first.

select
    Tweet.content,
    users.user_name,
    Tweet.twitted_at
from
    Tweet
    Join users on Tweet.user_id = users.id
where
    Tweet.user_id = 3
order by
    Tweet.twitted_at DESC; 
  1. Fetch like count of particular tweet by tweet id.
select
    count(*) as LikeCount
from
    Likes
where
    tweet_id = 2;

4. Fetch retweet count of particular tweet by tweet id.

select
    count(*) as RetweetCount
from
    Retweet
where
    parent_tweet_id = 2;

5. Fetch comment count of particular tweet by tweet id.

SELECT
    COUNT(*) AS CommentCount
FROM
    Tweet
WHERE
    parent_tweet_id = 1;

6. Fetch all users' names who have retweeted a particular tweet by tweet id.

select
    users.user_name
from
    Retweet
    JOIN users on Retweet.user_id = users.id
where
    Retweet.parent_tweet_id = 2;

7. Fetch all commented tweet’s content for particular tweet by tweet id.

SELECT
    CommentedTweet.content
FROM
    Tweet AS CommentedTweet
    JOIN Tweet AS Comment ON CommentedTweet.tweet_id = Comment.parent_tweet_id
WHERE
    Comment.parent_tweet_id = 2

8. Fetch user’s timeline (All tweets from users whom I am following with tweet content and user name who has tweeted it)

SELECT
    Tweet.content,
    users.user_name AS UserName
FROM
    Tweet
    JOIN users ON Tweet.user_id = users.id
WHERE
    Tweet.user_id IN (
        SELECT
            followed_id
        FROM
            Follow
        WHERE
            follower_id = 1
    )
ORDER BY
    Tweet.twitted_at DESC;

3-twitter-queries's People

Contributors

princesah09 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.