100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

CIS 2200 Joining Data in SQL Notes

Rating
-
Sold
-
Pages
5
Uploaded on
27-09-2024
Written in
2023/2024

This is a comprehensive and detailed note Joining Data in SQL for CIS 2200. *Essential Study Material!!

Institution
Baruch College
Course
CIS 2200









Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
September 27, 2024
Number of pages
5
Written in
2023/2024
Type
Class notes
Professor(s)
Prof. chowdhurry
Contains
All classes

Content preview

Joining Data in SQL

 We use joins to combine multiple tables within a query.
 The ON statement tells the SQL engine what columns to use to join the tables.
 Joins come after the FROM clause.

• Inner Join is the most common way to join data using SQL. An inner join includes only rows that have a match as specified
by the ON clause.

SELECT table1.column1, table1.column2, table2.column1,....
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;



• Left Join includes all rows from an inner join, plus any rows from the first table that don't have a match in the second table.

SELECT table1.column1, table1.column2, table2.column1,....
FROM table1
LEFT JOIN table2
ON table1.matching_column = table2.matching_column;



• Right Join includes all rows from the second table that don't have a match in the first table + any rows from an inner join.

SELECT table1.column1, table1.column2, table2.column1,....
FROM table1
LEFT JOIN table2
ON table1.matching_column = table2.matching_column;



• Full Outer Join includes all rows from both joined tables.

SELECT table1.column1, table1.column2, table2.column1,....
FROM table1
FULL JOIN table2
ON table1.matching_column = table2.matching_column;


SQLite doesn't support full outer joins or right joins.



Joins with Subqueries

,  Subqueries can be used to substitute parts of queries, allowing us to find the answers to more complex questions.
We can also join to the result of a subquery, just like we could a table.

 The result of a subquery is calculated first, so we read
from the inside out.




 This simple query selects all columns from cities, filtering rows that are marked as capital cities by having a value
for capital of 1.
 The INNER JOIN joins the subquery result, aliased as c, to the facts table based on the ON clause.
 Two columns are selected from the results of the join:
o f.name, aliased as country
o c.name, aliased as capital_city

 The results are limited to the first 10 rows.


Joining 3 Tables

• A schema diagram helps us understand the available columns and the
structure of the data. In a schema diagram, relationships are shown using
lines between tables.
• Each row's primary key must be unique.




Exercise: Write a query that gathers data about the invoice with an invoice_id of 4. Include the following columns in
order:
o The id of the track, track_id
o The name of the track, track_name
o The name of the media type of the
track, track_type
o The price that the customer paid for the
track, unit_price
o The quantity of the track that was
purchased, quantity




Joining 3+ Tables

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
anyiamgeorge19 Arizona State University
View profile
Follow You need to be logged in order to follow users or courses
Sold
60
Member since
2 year
Number of followers
16
Documents
7001
Last sold
2 weeks ago
Scholarshub

Scholarshub – Smarter Study, Better Grades! Tired of endless searching for quality study materials? ScholarsHub got you covered! We provide top-notch summaries, study guides, class notes, essays, MCQs, case studies, and practice resources designed to help you study smarter, not harder. Whether you’re prepping for an exam, writing a paper, or simply staying ahead, our resources make learning easier and more effective. No stress, just success! A big thank you goes to the many students from institutions and universities across the U.S. who have crafted and contributed these essential study materials. Their hard work makes this store possible. If you have any concerns about how your materials are being used on ScholarsHub, please don’t hesitate to reach out—we’d be glad to discuss and resolve the matter. Enjoyed our materials? Drop a review to let us know how we’re helping you! And don’t forget to spread the word to friends, family, and classmates—because great study resources are meant to be shared. Wishing y'all success in all your academic pursuits! ✌️

Read more Read less
3.4

5 reviews

5
2
4
0
3
2
2
0
1
1

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions