Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Needing some help with assignment 1 part of this assignment the data would all be used in SQL queries Users Table: CREATE TABLE Users (

Needing some help with assignment 1 part of this assignment the data would all be used in SQL queries Users Table: CREATE TABLE Users ( user_id INT PRIMARY KEY, username VARCHAR(50) NOT NULL, password VARCHAR(50) NOT NULL ); Tweets Table: CREATE TABLE Tweets ( tweet_id INT PRIMARY KEY, user_id INT NOT NULL, tweet_text VARCHAR(280) NOT NULL, timestamp DATETIME NOT NULL, FOREIGN KEY (user_id) REFERENCES Users(user_id) ); Followers Table: CREATE TABLE Followers ( follower_id INT PRIMARY KEY, follower_user_id INT NOT NULL, following_user_id INT NOT NULL, FOREIGN KEY (follower_user_id) REFERENCES Users(user_id), FOREIGN KEY (following_user_id) REFERENCES Users(user_id) ); Insert Data Let's insert five random users to the Users table: INSERT INTO Users (user_id, username, password) VALUES (1, 'JohnDoe', 'P@ssW0rd'), (2, 'JaneDoe', 'AVerySecurePassword'), (3, 'BobSmith', 'ILoveChicago'), (4, 'AliceJohnson', 'TestTest!'), (5, 'SamWilson', 'password2023'); INSERT INTO Tweets (tweet_id, user_id, tweet_text, timestamp) VALUES (1, 1, 'Just had the best burger ever! #yum #foodie', NOW()), (2, 1, 'Excited to see my favorite band in concert tonight!', NOW()), (3, 2, 'Working on a new project today. #programming #coding', NOW()), (4, 2, 'Just finished a great workout at the gym.', NOW()), (5, 3, 'Relaxing at the beach with a good book. #beachlife', NOW()), (6, 3, 'Trying out a new recipe for dinner tonight.', NOW()); INSERT INTO Followers (follower_id, follower_user_id, following_user_id) VALUES (1, 1, 2), (2, 1, 3), (3, 2, 1), (4, 2, 3), (5, 3, 1), (6, 4, 1), (7, 4, 3), (8, 5, 2), (9, 5, 4);

Query Data Ok, now that we have a few data points in our database, let's write a query to return all the tweets made by the user with the username of BobSmith:

SELECT t.tweet_id, u.username, t.tweet_text, t.timestamp FROM Tweets t INNER JOIN Users u ON t.user_id = u.user_id WHERE u.username = 'BobSmith'; Lab Assignment 1: Modify the above query to return all the tweets that are made by everyone else other than BobSmith. Sort the tweets by the time they have been created. This query would essentially build up the Twitter Timeline for BobSmith. Submit the query as part of your lab submission.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

Students also viewed these Databases questions

Question

Question What are the requirements for a SIMPLE 401(k) plan?

Answered: 1 week ago