ஒரு பார்வை

June 23, 2006

My Notes – SQL

Filed under: SQL — CAPitalZ @ 11:03 am

This Transact-SQL query is an example of an inner join:

USE pubs
SELECT *
FROM authors AS a INNER JOIN publishers AS p
   ON a.city = p.city
ORDER BY a.au_lname DESC

This inner join is known as an equi-join. It returns all the columns in both tables, and returns only the rows for which there is an equal value in the join column.

======

Sub Queries That Return No Rows

… When creating tables, it can be very useful to write the SQL to use a sub query which will not return any rows – when just the table structure is required and not any of the data.

In the following example we create a copy of the policy table with no rows:

CREATE TABLE new_policy AS
(SELECT * from policy WHERE FALSE=TRUE);

The sub query returns no data but does return the column names and data types to the ‘create table‘ statement.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: