Cartesian product of T1 and T2 (all possible pairs/combos of rows from each of the two tables). Select * from t1,t2; N*M pairs where N and M are number of rows of the two tables, respectively. Cartesian product usually not useful! (it's the basis of a join) select count(*) from t1,t2; select * from t1,t2 order by fj desc; select fi,count(*) from t1,t2 group by fi; select * from t1,t2 where fi>=2; ************************************************************* A join is the Cartesian product with the rows that do not meet a matching column condition removed. A join is a subset of the Cartesian product. two (or more) tables are joined together, typically on common fields e.g. PK and FK. "Heart of SQL", "the real power behind the relational database". The common field is the link between the tables. Form pairs of rows by matching the contents of related columns. Joins exercise the data relationships between tables. Are the only way to exercise cross-table relationships. When need to pull data from multiple tables to answer a query. Any pair of columns from the two tables can serve as matching columns, provided they have comparable data types but most often the common fields are the primary key of "parent" table and foreign key in the "child" table that references that primary key. "Natural join": selects only the rows with common values in the common attribute. ** SELECT ...FROM parent,child WHERE parent.pk=child.fk ... The From clause lists the tables being joined. The Where clause specifies the matching condition, and possibly further restrictions. Order of t1,t2 makes no difference. Any columnname that's in both tables must be qualified by tablename to disambiguate it: t1.fi if there's a fi in t2 too. Sometimes qualifiers helpful for readability. SELECT ... FROM t1,t2 WHERE t1.fi=t2.fi ... Examples: Cartesian products: For demonstration purposes only. Not useful. select count(*) from pet,event; select * from pet,event limit 2; #notice name is twice select pet.name,species,sex,type,remark from pet,event; select * from pet,event; Joins: 'name' is the common field of the pet and event tables. Use it to join. #combine the pet data into each event: SELECT Count(*) FROM pet,event WHERE pet.name=event.name; SELECT * FROM pet,event WHERE pet.name=event.name; #sex of the pets that had litters duh SELECT pet.name,sex,date FROM pet,event WHERE pet.name=event.name AND type='litter'; #owners whose pets have had birthdays: SELECT DISTINCT owner FROM pet,event WHERE pet.name=event.name AND type='birthday'; #Harold's pets' event: SELECT pet.name,type,date FROM pet,event WHERE pet.name=event.name AND owner='harold'; #age of pets on visits: SELECT pet.name,type,DATEDIFF(date,birth)/365 AS age FROM pet,event WHERE pet.name=event.name ; #pets who visited when less than year old: SELECT pet.name,type,birth,date FROM pet,event WHERE pet.name=event.name AND DATEDIFF(date,birth)<365;