Updating Data from other tables

Hello-

I have 3 tables:
tblHomes
tblGeo
tblMLS

tblHomes and tblGeo are connected via the listID from tblhomes. TblGeo has the ListID and Lat, long values for each record in tblHomes.

I need to update the Lat and long values based on the lat and long values from tblMLS. TblMLS and tblHomes are connected via the ListNumber but not listID. How can I create a query to do automatic updates of data from one table to another?
This gives me the ListNumber, Latitude and longitude. How do i then insert this into tblGeo and include the ListID from tblHomes.
Select MLS_Listing_Number, Latitude, Longitude from tblMLS where latitude <> '' and longitude <> '' and MLS_Listing_Number in(Select ListingNumber from tblhomes where Active='1')
jfergyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David ToddSenior DBACommented:
Hi,

      m.MLS_Listing_Number
      , h.ListID
      , m.Latitude
      , m.Longitude
from tblMLS m
inner join tblHomes h
      on h.MLS_Listing_Number = m.MLS_Listing_Number
where
      m.latitude <> ''
      and m.longitude <> ''
      and m.MLS_Listing_Number in
            (
            Select ListingNumber
            from tblhomes
            where Active='1'
            )

Now that can get turned into an update

Cheers
  David
0
David ToddSenior DBACommented:
Whoops, copy and paste error

select
      m.MLS_Listing_Number
      , h.ListID
      , m.Latitude
      , m.Longitude
from tblMLS m
inner join tblHomes h
      on h.MLS_Listing_Number = m.MLS_Listing_Number
where
      m.latitude <> ''
      and m.longitude <> ''
      and m.MLS_Listing_Number in
            (
            Select ListingNumber
            from tblhomes
            where Active='1'
            )
0
David ToddSenior DBACommented:
Hi,

Update.

update g
set
      g.Latitude = m.Latitude
      , g.Longitude = m.Longitude
from tblGeo g
--select
--      m.MLS_Listing_Number
--      , h.ListID
--      , m.Latitude
--      , m.Longitude
from tblMLS m
inner join tblHomes h
      on h.MLS_Listing_Number = m.MLS_Listing_Number
inner join tblGeo g
      on g.ListID = h.ListID
where
      m.latitude <> ''
      and m.longitude <> ''
      and m.MLS_Listing_Number in
            (
            Select ListingNumber
            from tblhomes
            where Active='1'
            )

Your text asks for an update, but also uses the word insert. Which one?

Cheers
  David
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jfergyAuthor Commented:
David-

It's both actually but the update is fine.

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.