Monday, August 12, 2013

Joins

Inner Join: join the information you want into a new temporary table

Distinct guarantees that you only have values printed out once.

mysql>SELECT DISTINCT Manufacturer_ID.Manufacturer,Manufacturer_ID.Man_ID
/*The table is on the left side of the "." and it's column is on the right side of the dot. All the tables with their respective columns that we want to join are separated by commas.*/

    ->FROM Manufacturer_ID, Model_Numbers
/*Define the tables that I want to pull this from. Ending with a colon at this point would make a full join, but we are going to perform an innerjoin*/

    ->WHERE ((Manufacturer_ID.Man_ID = Model_Numbers.Man_ID) AND (Model_Numbers.PT_ID = 32))
/*An innerjoin has clauses that will define what information is needed*/

    ->ORDER BY Manufacturer;
/*Print all that to screen in alphabetiacl order based off of the manufacturer */

No comments:

Post a Comment