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
 inner join...

Author  Topic 

sqlneve
Starting Member

16 Posts

Posted - 2008-12-10 : 09:38:25
i want to do an inner join (i think) but the table i want to join to is itself. can anyone point me in the right direction on this? i'm such a newb!

In my table I want to know where address' are the same, id's are the same but longitude is different. so all i have is the end part of the query


Select*
From txall
inner join txall
on id = id
and address1 = address1
and city = city
and longi <> longi
and county = 'williamson'


can anyone help me out

thanks!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-10 : 09:45:57
[code]SELECT address1
city,
COUNT(*)
FROM txAll
WHERE county = 'Willimason'
GROUP BY address1
city
HAVING MIN(longi) < MAX(longi)
OR MIN(lati) < MAX(lati)
ORDER BY city,
address1[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sqlneve
Starting Member

16 Posts

Posted - 2008-12-10 : 09:54:00
The Count (*) is throwing an incorrect syntax error????
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-12-10 : 09:54:56
put a comma after address1 in select
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-12-10 : 09:55:59
and one after address1 again in group by clause. Also, do you have lati column with you ?
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-12-10 : 09:57:24
[code]select id,address1,city,count(distinct longitude)
from
txall
group by id,address1,city
having count(distinct longitude)>1[/code]
Go to Top of Page

sqlneve
Starting Member

16 Posts

Posted - 2008-12-10 : 09:59:07
Yes, I do have a lat column as well but not a lati. (I caught that as well) I added the comma and double checked all other areas where i thought there might need to be one but the error keeps coming up.

Thank you all so much for working with me on this! I can't tell you how much I have been learning in here.
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2008-12-10 : 10:04:34
whats the error when you run this ?
select 
id,address1,city,count(distinct longitude),count(distinct lat)
from
txall
group by
id,address1,city
having
count(distinct longitude)>1 or
count(distinct lat)>1
Go to Top of Page

sqlneve
Starting Member

16 Posts

Posted - 2008-12-10 : 10:22:20
No error! Thank you so much
Go to Top of Page
   

- Advertisement -