• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

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')
0
jfergy
Asked:
jfergy
  • 3
1 Solution
 
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
 
jfergyAuthor Commented:
David-

It's both actually but the update is fine.

Thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now