When joining related tables in a query, it is important to understand how duplicate records can be returned and how to return only distinct records instead.
- [Instructor] In this movie, we will learn…how we could end up with duplicate records…from a joined query, and now to handle it when you do.…When we use the joins method, the SQL that it writes…is an SQL inner join.…And that's a particular type of join in SQL.…We're going to talk more about another type in a moment.…But for now, let's talk about some of the characteristics…of using an inner join.…As we already saw, it makes a related table…available in a query.…It also has two other characteristics.…One is that it can create duplicate entries,…and you may have noticed that in the last movie.…
We'll talk more about that in just a moment.…It's primarily a concern when we have a one to many…relationship, or a has_many relationship in Rails.…And the second characteristic is that it includes…only records which have the relationship.…Records which do not have the relationship…will be omitted from the results.…We're going to talk about this more in the following movie.…For now I want us to focus on that third bullet point,…
Author
Released
1/27/2017- Migrating databases
- Creating, updating, and deleting records
- Tracking changes to objects and attributes
- Writing queries
- Delegating attributes
- Callbacks
- Working with associations
Skill Level Intermediate
Duration
Views
Related Courses
-
Ruby: Testing with RSpec
with Kevin Skoglund6h 13m Intermediate -
Ruby on Rails 5 Essential Training
with Kevin Skoglund10h 21m Beginner -
Ruby Essential Training
with Kevin Skoglund6h 57m Beginner
-
Introduction
-
Welcome1m
-
-
1. Database Migrations
-
Create a database5m 43s
-
Migration shortcuts8m 19s
-
The change method4m 27s
-
Write reversible code4m 10s
-
Irreversible migrations4m 39s
-
Revert migrations4m 21s
-
Create a join table4m 38s
-
Control migration output7m 39s
-
Dump the database schema4m 52s
-
Define seed data4m 52s
-
-
2. CRUD Methods
-
Create records with a block2m 29s
-
Update multiple records5m 56s
-
Delete multiple records3m 24s
-
Touch records3m 47s
-
Toggle attribute values2m 10s
-
-
3. Dirty Objects
-
Track changes to objects5m 6s
-
Track changes to attributes4m 43s
-
Restore attributes4m 6s
-
-
4. Query Interface
-
Other find methods8m 2s
-
Select partial record data5m 31s
-
Calculations5m 15s
-
Negative queries3m 20s
-
Or queries46s
-
Retrieve records in batches5m 43s
-
Default scopes6m 49s
-
Join tables8m 13s
-
Distinct records4m 42s
-
Left join tables6m 2s
-
Eager loading9m 7s
-
-
5. Delegations
-
Delegate attributes8m 34s
-
Set a prefix2m 13s
-
Without a related object3m 26s
-
-
6. Callbacks
-
Callback basics8m 35s
-
Conditional callbacks3m 52s
-
Around callbacks4m 41s
-
Other callbacks and tips4m 6s
-
-
7. Associations
-
Review3m 28s
-
Destroy associated records7m 52s
-
Touch associated records5m 47s
-
Counter caches9m 39s
-
Single table inheritance11m 49s
-
Polymorphic associations5m 34s
-
-
Conclusion
-
Next steps21s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Distinct records