Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:16:39+00:00 2026-05-24T16:16:39+00:00

Places Table PlaceId PK Name GeoPoint (GeoPoint type) etc… PlaceCats Table (the join table)

  • 0

Places Table

  • PlaceId PK
  • Name
  • GeoPoint (GeoPoint type)
  • etc…

PlaceCats Table (the join table)

  • PlaceId PK FK
  • CatId PK FK

PlaceCategories Table

  • CatId PK
  • Name
  • etc…

Here’s my query, to return places, with entries in the PlaceCats table (by a series of catIds), and within 25km of a Lat/Lng value.

SELECT Places.* 
FROM Places 
     INNER JOIN PlaceCats 
             ON Places.PlaceId = PlaceCats.PlaceId 
WHERE PlaceCats.CatId IN (2,3,4,5) 
AND Places.GeoPoint.STDistance(geography::Point(35.75094975999387, 139.39780220389366, 4326)) < ((25 * 1000)) 
ORDER BY Places.Name ASC

It’s returning places, but I need to add DISTINCT after the SELECT… apparently you can’t use DISTINCT when selecting geography data. I need to make sure I’m not getting the same place multiple times (as they can have multiple entries in the join table).

Update

When I insert a place into the Places table, the GeoPoint is set like so:

SqlGeography.Point(sentPlace.Lat.Value, sentPlace.Lng.Value, 4326);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:16:41+00:00Added an answer on May 24, 2026 at 4:16 pm

    It look to me like you have your long/lats the wrong way round.

    As for selecting DISTINCT geographies, you can perform the DISTINCT operation over the WKT (Well Known Text) in a nested query, see below:

    SELECT 
    GEOGRAPHY::STGeomFromText(WKT, [PROJECTION]) AS GEOG
    FROM
    (
        SELECT DISTINCT
        GEOG.STAsText() AS WKT
        FROM 
        [TABLE_NAME]
    ) a
    

    Your query would look something like this:

    SELECT 
        a.* 
    ,   GEOGRAPHY::STGeomFromText(WKT, 4326) AS GEOG
    FROM 
    (
        SELECT DISTINCT
            Places.[COL1]
        ,   Places.[COL2]
        ,   Places.[COL3]
        ,   Places.[COL4]
        ...
        ...
        ,   Places.GeoPoint.STAsText() AS WKT
        FROM 
        Places 
        INNER JOIN 
        PlaceCats 
        ON 
        Places.PlaceId = PlaceCats.PlaceId 
        WHERE PlaceCats.CatId IN (2,3,4,5) 
        AND 
        Places.GeoPoint.STDistance(GEOGRAPHY::Point(35.75094975999387, 139.39780220389366, 4326)) < ((25 * 1000)) 
        ORDER BY Places.Name ASC 
    )a 
    

    One further tip, assuming you have a spatial index on your table, it speeds spatial queries up no end by using an index hit:

    SELECT *
    FROM 
    [TABLE_NAME] WITH(INDEX([INDEX_NAME]))
    WHERE
    GEOG.STIntersects.(GEOGRAPHY::Point([Longitude], [Latitude], 4326)) = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to query a mysql table which places its date in the following
I have two databases at two different places, both databases are same with table
I has a page as follow: <table> <tr> <th>Company Name</th> </tr> <tr> <td><a href=www.whatever.com>
I have Account ID(Select),Account Name, Percentage(Text) and Total columns in the JQuery Table. Whenever
I'm trying to make a PIVOT-query out of a working table with the structure:
I query a MySql table with 5 different records. Then I fill a VB6
So I have three tables: Table Place: _id autoincrement not null primary key, name
I want to place a table on my page. I have two tables in
What is everyone's recommendations on where to place database objects (tables, procs, views etc.)
In many places, (1,2,3) (a tuple) and [1,2,3] (a list) can be used interchangeably.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.