Ville,

as you are probably aware, there are no subselects in MySQL. Therefore, you
will probably have to retrieve the additional waypoints through a second
query. (As an aside: there may exist a solution using self-joins, but from
looking at the problem I don't think so)

I assume you will be using an API and a programming language. Then you could
simply go and say (for Perl DBI):

SELECT * FROM waypoints WHERE path = ? and (waypoint_nr = ? -1 or
waypoint_nr = ? + 1)

Parametrize that with the information from your first result set for each of
its rows. Merge all the result sets retrieved and eliminate duplicate
combinations of path and waypoint, and there you are. Pretty ugly but
workable, I think. In fact using Perl hashes even easy to do.

However, whether this approach is feasible for you depends entirely on what
combination of API and language/tool you are using for your development.
Also, there may be better solutions. If so, the list will probably point
them out to you. ;-)

Cheers,
Christian Sage

-----Ursprüngliche Nachricht-----
Von: Ville Mattila [mailto:[EMAIL PROTECTED]]
Gesendet: Samstag, 8. September 2001 18:17
An: MySQL-mailinglist
Betreff: SELECT-problem


Hi there,

This is my problem now... I have a table containing different paths, like
this:

+------+----+---+------------+
| Path | X  | Y | WaypointNr |
+------+----+---+------------+
| P1   |  1 | 5 |          1 |
| P1   |  2 | 6 |          2 |
| P1   |  3 | 7 |          3 |
| P1   |  8 | 3 |          4 |
| P2   | 11 | 4 |          1 |
| P2   |  7 | 3 |          2 |
| P2   |  5 | 2 |          3 |
| P2   |  2 | 1 |          4 |
+------+----+---+------------+


I need to draw a map from these paths, so I make a following query to get
waypoints and paths located in defined area (where the corners are (3,2) and
(7,6).

mysql> SELECT * FROM waypoints WHERE X > 2 AND X < 8 AND Y > 1 AND Y < 7;
+------+---+---+------------+
| Path | X | Y | WaypointNr |
+------+---+---+------------+
| P2   | 7 | 3 |          2 |
| P2   | 5 | 2 |          3 |
+------+---+---+------------+

That's OK... but now I would like to get also those waypoints which ones are
next to these results (on the same path). In this case, I want also points 1
and 4 on P2. How?

Emm... Hope that you could understand even something. ;)

- Ville

.................................................................
Ville Mattila
Ikaalinen, Finland
[EMAIL PROTECTED]



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to