Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL query

Author  Topic 

ag_ss
Starting Member

48 Posts

Posted - 2006-03-29 : 00:31:20
hi

SELECT * FROM (SELECT DISTINCT attr FROM iba UNION SELECT DISTINCT attr FROM new_iba) WHERE attr != 0;

this query is working with oracle not with MS SQL

can u tell me whats wrong init

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-29 : 00:35:01
[code]SELECT * FROM (SELECT DISTINCT attr FROM iba UNION SELECT DISTINCT attr FROM new_iba) t WHERE attr != 0[/code]



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

ag_ss
Starting Member

48 Posts

Posted - 2006-03-29 : 00:39:28
it worked thanx
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-29 : 00:43:03
You will need to named the derived table



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

ag_ss
Starting Member

48 Posts

Posted - 2006-03-29 : 00:44:58
sorry i didnt get u
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-29 : 00:53:34
The only changes i did is add a t before the WHERE.

This is a derived table :
(SELECT DISTINCT attr FROM iba UNION SELECT DISTINCT attr FROM new_iba)

The derived table must be given an alias name. In this case, I simply use t




KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-29 : 01:08:37
This is extracted from the SQL Server Books On Line for you further reference.
quote:
Using the FROM Clause
The FROM clause is required in every SELECT statement in which data is being retrieved from tables or views. Use the FROM clause to:

List the tables and views containing the columns referenced in the select list and in the WHERE clause. The table or view names can be aliased using the AS clause.


Join types. These are qualified by join conditions specified in the ON clause.
The FROM clause is a comma-separated list of table names, view names, and JOIN clauses.

Transact-SQL has extensions that support the specification of objects other than tables or views in the FROM clause. These other objects return a result set, or rowset in OLE DB terms, that form a virtual table. The SELECT statement then operates as if the result set were a table.

The FROM clause can specify:

One or more tables or views. For example:
SELECT *
FROM Shippers


Joins between two tables or views:
SELECT Cst.CustomerID, Cst.CompanyName, Cst.ContactName,
Ord.ShippedDate, Ord.Freight
FROM Northwind.dbo.Orders AS Ord
JOIN
Northwind.dbo.Customers AS Cst
ON (Cst.CustomerID = Ord.CustomerID)


One or more derived tables, which are SELECT statements in the FROM clause referred to by an alias or a user-specified name. The result set of the SELECT in the FROM clause forms a table used by the outer SELECT statement. For example, this SELECT uses a derived table to find if any store carries all book titles in the pubs database:
SELECT ST.stor_id, ST.stor_name
FROM stores AS ST,
(SELECT stor_id, COUNT(DISTINCT title_id) AS title_count
FROM sales
GROUP BY stor_id
) AS SA
WHERE ST.stor_id = SA.stor_id
AND SA.title_count = (SELECT COUNT(*) FROM titles)






KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

a_r_satish
Yak Posting Veteran

84 Posts

Posted - 2006-03-29 : 01:11:01
(SELECT DISTINCT attr FROM iba UNION SELECT DISTINCT attr FROM new_iba)

Another note, this in your query acts as a virtual table.. You can also create virtual fields in the similar manner.. This concepts are very important to develop ur knowledge in querrying.

Regards,
satish.r
"Known is a drop, Unknown is an Ocean"
Go to Top of Page

ag_ss
Starting Member

48 Posts

Posted - 2006-03-29 : 01:15:41
one more thing how to call .sql file from another .sql file
in oracle i user

@<path>/xxx.sql
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-29 : 01:45:16
quote:
Originally posted by ag_ss

one more thing how to call .sql file from another .sql file
in oracle i user

@<path>/xxx.sql


It has been posted as new thread here http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=63877



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page
   

- Advertisement -