Board index » delphi » Query problem: does anyone know?

Query problem: does anyone know?

Hello there,

I have the following problem with a Query.
I have two tables :

Table1: Name, Xpos, Ypos

Table2: Name1, Name2

With these two tables i want to construct a query that has the following
characteristics

QueryTable: Xpos1, Ypos1, Xpos2, Ypos2.

From table1 with i want to get the xpos and ypos for name1 and name2
from table2
This way I get a table with the coordinates of the two objects.

Tanks alot for any help, Darius Blaszijk

 

Re:Query problem: does anyone know?


"Darius Blaszijk" <DBlasz...@ZonNet.nl> skrev i melding
news:3911F02B.E5BA4260@ZonNet.nl...

Quote

> Table1: Name, Xpos, Ypos

> Table2: Name1, Name2

> With these two tables i want to construct a query that has the following
> characteristics

> QueryTable: Xpos1, Ypos1, Xpos2, Ypos2.

> From table1 with i want to get the xpos and ypos for name1 and name2
> from table2

Hi !

You need to "double" join Table 1 with Table2, and use field aliases if you
want the result to have the field names like you suggested (but I assume you
want the names selected as well..:

SELECT
  T2.Name Name1, // Field alias
  P1.Xpos Xpos1,
  P1.Ypos YPos1,
  T2.Name Name2,
  P2.Xpos Xpos2,
  P2.Ypos YPos2
FROM
  Table2 T2, // Table alias
  Table1 P1,
  Table1 P2
WHERE
  P1.Name = T2.Name1
AND
  P2.Name = T2.Name2

...untested...;-)

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:Query problem: does anyone know?


Use:

SELECT Table1.XPos AS Xpos1, Table1.YPos AS Ypos1, Table1a.XPos AS Xpos2,
Table1a.YPos AS Ypos2
FROM Table1, Table1 Table1a, Table2
WHERE Table1.Name = Table2.Name1
AND Table1a.Name = Table2.Name2

"Darius Blaszijk" <DBlasz...@ZonNet.nl> schreef in bericht
news:3911F02B.E5BA4260@ZonNet.nl...

Quote
> Hello there,

> I have the following problem with a Query.
> I have two tables :

> Table1: Name, Xpos, Ypos

> Table2: Name1, Name2

> With these two tables i want to construct a query that has the following
> characteristics

> QueryTable: Xpos1, Ypos1, Xpos2, Ypos2.

> From table1 with i want to get the xpos and ypos for name1 and name2
> from table2
> This way I get a table with the coordinates of the two objects.

> Tanks alot for any help, Darius Blaszijk

Other Threads