Add Tables to Queries (Visual Database Tools)
Applies to: SQL Server
When you create a query, you are retrieving data from a table or other objects structured like tables - views and certain user-defined functions. To work with any of these objects in your query, you add them to the Diagram Pane.
To add a table or table-valued object to a query
In the Diagram pane of the Query and View Designer, right-click the background and choose Add Table from the shortcut menu.
In the Add Table dialog box, select the tab for the type of object you want to add to the query.
In the list of items, double-click each item you want to add.
When you finish adding items, click Close.
The Query and View Designer updates the Diagram Pane, Criteria Pane, and SQL Pane accordingly.
Tables and views are automatically added to the query when you reference them in the statement in the SQL pane.
The Query and View Designer will not display data columns for a table or table-structured object if you do not have sufficient access rights to it or if the provider cannot return information about it. In such cases, only a title bar and the * (All Columns) check box are displayed for the table or table-valued object.
To add an existing query to a new query
Make sure the SQL Pane is displayed in the new query you are creating.
In the SQL Pane, type a right and left parentheses () after the word FROM.
Open the Query Designer for the existing query. (You now have two Query Designers open.)
Display the SQL Pane for the inner query - the existing query you are including in the new, outer query.
Select all the text in the SQL Pane, and copy it to the Clipboard.
Click in the SQL Pane of the new query, situate the cursor between the parentheses you added, and paste the contents of the Clipboard.
Still in the SQL Pane, add an alias after the right parenthesis.
See Also
Create Table Aliases (Visual Database Tools)
Remove Tables from Queries (Visual Database Tools)
Specify Search Criteria (Visual Database Tools)
Summarize Query Results (Visual Database Tools)
Perform Basic Operations with Queries (Visual Database Tools)