Performing Queries Using SQL |
Querying Multiple
Tables |
As in a query for a single table, the WHERE clause in the
SELECT statement selects rows, from two or more tables, based on a
condition.When you join multiple tables, be sure to specify matching columns
in the WHERE clause to avoid unwanted combinations.
In this example, the WHERE clause selects only rows that have matching values for ID. (You can specify columns in the WHERE clause that are not specified in the SELECT clause.) |
proc sql; select bldginfo.id,lastname,building,room,extension from emplib.payroll,emplib.bldginfo where bldginfo.id=payroll.id order by lastname; |
ID | LastName | Bldg | Rm | Ext |
1002 | BOWMAN | B | 34 | 2782 |
1007 | BROWN | A | 48 | 0342 |
1049 | FERNANDEZ | D | 22 | 1347 |
1006 | GARRETT | D | 16 | 2209 |
1077 | GIBSON | B | 17 | 1697 |
1008 | HERNAND | A | 19 | 6391 |
1009 | JONES | C | 24 | 3857 |
1005 | KNAPP | B | 98 | 5917 |
1004 | KNIGHT | C | 13 | 6718 |
1074 | MILLSAP | C | 56 | 1543 |
1012 | QUINTERO | B | 30 | 7518 |
1003 | SALAZAR | A | 65 | 2771 |
1083 | SAVAGE | A | 22 | 7357 |
1015 | SCHOLL | C | 49 | 3756 |
1010 | SMITH | B | 37 | 2134 |
1011 | VAN HOTTEN | A | 51 | 2649 |
1017 | WAGGONNER | C | 26 | 2719 |
1001 | WATERHOUSE | A | 57 | 2345 |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.