[posted and mailed, please reply in news]
John Paine (jpaine@bigpond.net.au) writes:
[quoted text, click to view] > I've been struggling with how best to define a query to get a list of
> unique coordinates from a database table and my SQL skills are not good
> enough to work out a good solution. The basic table structure is as
> follows:
>
> CREATE TABLE [Readings Data Table] (
> CY DOUBLE,
> PY DOUBLE,
> C1X DOUBLE, C2X DOUBLE,
> P1X DOUBLE, P2X DOUBLE)
>
> Each record in the table represents a geophysical measurement for a
> sensors at the four locations (P1X,PY), (P2X,PY), (C1X,CY) and (C2X,CY).
> There can be many repeat readings (ie with the same locations) and many
> overlapped readings (ie which share at least one sensor location) and an
> example set of data is:
In general, for this type of queries it is a good advice to post:
o CREATE TABLE statement for the involved table(s). (Which you did,
thank you.)
o INSERT statements with sample data.
o The desired output given the sample data. (Which you did, thanks!)
This makes it easy for anyone who takes a stab at your problem to post
a tested solution, because it's easy to cut and paste into Query
Analyzer.
Since there is no INSERT statements for the data, this is an untested
solution:
SELECT P1X, PY FROM [Readings Data Table}
UNION
SELECT P2X, PY FROM [Readings Data Table}
UNION
SELECT C1X, CY FROM [Readings Data Table}
UNION
SELECT C2X, CY FROM [Readings Data Table}
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at