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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Is it possilble to use the query like this

Author  Topic 

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-04-26 : 01:43:35
hai,
usually we can join two tables to get the expected result..

select B.name from
(select name,createddate from tbl1 group by createddate,name)B
The above is possible...
But in the same above query can i use inner join with the same B table.

say,
select B.name from
(select name,createddate from tbl1 group by createddate,name)B
inner join
B as Renametable
on Renametable.name = 'Shyam'


madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-26 : 01:51:58
You can simply write

select B.name from
(select name,createddate from tbl1 group by createddate,name)B
where name = 'Shyam'

or

select B.name from
(select name,createddate from tbl1 where name = 'Shyam' group by createddate,name)B



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-04-26 : 01:57:25
In my requirement i want to treat this B as two different table and compare something...
that's y i asked is it possible to use
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-04-26 : 02:03:28
I dont think by doing this will get the expected result, since it will cross join between both the tables..

Somthing like this..

select B.name from
(select Pk,name,createddate from tbl1 group by createddate,name)B
inner join
B as Renametable
on Renametable.[Pk]= b.[Pk] and Renametable.name = 'Shyam'


If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-26 : 02:05:19
You can inner join with other table as

select B.name from
(select name,createddate from tbl1 group by createddate,name)B
inner join OtherTable O on B.name=O.name

Otherwise you need to use the same query twice

select B.name from
(select name,createddate from tbl1 group by createddate,name)B
inner join
(select name,createddate from tbl1 group by createddate,name)C
on B.name=C.name

or move the result to temp table and do query based on it

Insert into #temp
select name,createddate from tbl1 group by createddate,name

select B.name from #temp B inner join #temp C
on B.name=C.name where B.name='Somename'

Otherwise post your exact requirement


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Sarakumar
Posting Yak Master

108 Posts

Posted - 2006-04-26 : 02:16:44
Thanks a lot
Go to Top of Page
   

- Advertisement -