Yes; great point. We would need to have a different database representation, and the primary key for the CREDIT table would have to include the role. Modelling the world is hard.
No.
Yes and yes. We'll do the first soon if not today. The latter is more rare, but quite possible.
I suppose it depends on the question being asked. But if I ask the registrar for people who are in both 204 and 304, I typically want names, not B-numbers.
OUTER JOIN gives you NULL for rows that have no match.
INNER JOIN omits rows that have no match. So your last sentence is correct.
Using INNER JOIN to merge tables using a 1:1 key would give us: min(a,b) to max(a,b) rows, or maybe a+b? Using INNER JOIN to merge tables using a 1:N key would give us: at most a*b rows Using INNER JOIN to merge tables using a N:N key would give us: also a*b rows??"
MIN for the first.
B for the second (can't have more rows than there are in the "many" table)
For many-many, we'd use an intermediate table, basically representing it as two 1:N mappings. So the size of the intermediate table.
By thinking about it as a cross-product, we can think about joins in a more general way, allowing some more creative uses. For example, finding possible co-star relationships (actors joined with actors).
SELECT * FROM person INNER JOIN movie ON (person.nm = movie.director)compared to
SELECT * FROM person INNER JOIN movie ON (nm = director)Meaning, what happens when there is no dot operator used to specify a table in that ON conditions?
If you are joining two tables and there is only one column
named director
among the two tables, so that the
name director
is unique and unambiguous, you can
say director
and not movie.director
,
omitting the name of the table that it is in.
If it's not unique, you have to specify.
So the latter is a perfectly equivalent shorthand for the first.
select * from person, movie where nm = directoris it implied for the SQL query to recognize that nm belongs to person and director belongs to the movie table?
yes
We don't loop in SQL. Sometimes, we build more complex subqueries. More later.
Yes. I (Scott w/ UID=1) have added many movies.
No lists. Each movie says who added it.
No copies; just aliases. The purpose is to allow pairs from the same table. You don't like the co-stars example? How about pairs of classes that conflict?
select A.crn, B.crn where A.meeting_time = B.meeting_time;
Each table needs a name, so we can refer to its columns. If the table is used twice, we need an alias for it.
Well, we delete rows, not keys. We'll learn that soon. But we also need to learn about referential integrity.
Sure. It's in the plan.
SELECT * FROM owner INNER JOIN pet ON (owner.oid = pet.oid) ...the same as
SELECT * FROM pet INNER JOIN owner ON (owner.oid = pet.oid) ...
Order does not matter in that case.