SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Performing Queries Using SQL
Querying Multiple Tables  


Specifying Columns That Appear in Multiple Tables

To join two or more tables, you must specify a prefix in the SELECT statement if both tables that you are querying contain like-named columns.

In the SELECT statement below, the SELECT clause specifies the prefix BldgInfo for the column ID. Both of these tables contain the column ID for employee identification numbers. The prefix specifies the tables from which you want the column to be read.

     proc sql;
        select bldginfo.id,lastname,building,room,extension
           from emplib.payroll,emplib.bldginfo
           where bldginfo.id=payroll.id
           order by lastname;
In this case, the column ID is read from EmpLib.BldgInfo. For columns that are not like-named, simply specify the column name. Separate all column names with commas.


back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement