pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How To Use JOIN?
3+ messages / 3 participants
[nested] [flat]

* How To Use JOIN?
@ 1998-11-17 16:05 Takashi Tokunaga <taka-tok@chaos.digital-magic.co.jp>
  1998-11-17 16:36 ` Re: [SQL] How To Use JOIN? Herouth Maoz <herouth@oumail.openu.ac.il>
  1998-11-17 17:43 ` Re: [SQL] How To Use JOIN? Oliver Elphick <olly@lfix.co.uk>
  0 siblings, 2 replies; 3+ messages in thread

From: Takashi Tokunaga @ 1998-11-17 16:05 UTC (permalink / raw)
  To: pgsql-sql

Hello PGSQL users, I'm having trobule using join statement:

I've created two tables and trying to compare contents of two 
tables and receive results which found on two tables equaled.

------Here's what I did ------

1. I create two tables:

  create table test1 (
    name_1  varchar(10),
    code_1 int
  )\g
  
  create table test2 (
   name_2  varchar(10),
   code_2 int
  )\g

2. Entered sample data:

  insert into test1 values ( '10', 1) \g
  insert into test1 values ( '11', 2) \g

  insert into test2 values ( '11', 1) \g
  insert into test2 values ( '11', 2) \g

3. Now after that worked without any problem, so I now create SELECT
   statement:

  select * from test1 test2 where code_1 = test.code_2 \g
  ERROR:  attribute 'code_2' not found

nope that didn't work
  
  select test1.name_1 from test1 test2 where test1.code_1 = test2.code_2 \g
  ERROR:  attribute 'code_2' not found

Umm... still no change.

------

Mmm... Any ideas? 
If I can get value of test1.name_1 which also had equal value on code_1 
and test2.code_2, I'll solve my trouble.  It shouldn't be that complex but it's
been driving me nuts for few hours.

I'm using postgresql-6.3.2 under FreeBSD 2.2.6.

Thanx in Advance,

Takashi





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] How To Use JOIN?
  1998-11-17 16:05 How To Use JOIN? Takashi Tokunaga <taka-tok@chaos.digital-magic.co.jp>
@ 1998-11-17 16:36 ` Herouth Maoz <herouth@oumail.openu.ac.il>
  1 sibling, 0 replies; 3+ messages in thread

From: Herouth Maoz @ 1998-11-17 16:36 UTC (permalink / raw)
  To: Takashi Tokunaga <taka-tok@chaos.digital-magic.co.jp>; +Cc: pgsql-sql

At 18:05 +0200 on 17/11/98, Takashi Tokunaga wrote:


> 3. Now after that worked without any problem, so I now create SELECT
>    statement:
>
>   select * from test1 test2 where code_1 = test.code_2 \g
>   ERROR:  attribute 'code_2' not found
>
> nope that didn't work
>
>   select test1.name_1 from test1 test2 where test1.code_1 = test2.code_2 \g
>   ERROR:  attribute 'code_2' not found

You seem to have forgotten a comma...

SELECT *
FROM test1, test2   <---- Here
WHERE code1 = code2;

if you don't put a comma, "test2" will be used as an alias to "test1", not
as a table on its own.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] How To Use JOIN?
  1998-11-17 16:05 How To Use JOIN? Takashi Tokunaga <taka-tok@chaos.digital-magic.co.jp>
@ 1998-11-17 17:43 ` Oliver Elphick <olly@lfix.co.uk>
  1 sibling, 0 replies; 3+ messages in thread

From: Oliver Elphick @ 1998-11-17 17:43 UTC (permalink / raw)
  To: Takashi Tokunaga <taka-tok@chaos.digital-magic.co.jp>; +Cc: pgsql-sql

Takashi Tokunaga wrote:
  >Hello PGSQL users, I'm having trobule using join statement:
 
  >3. Now after that worked without any problem, so I now create SELECT
  >   statement:
  >
  >  select * from test1 test2 where code_1 = test.code_2 \g
  >  ERROR:  attribute 'code_2' not found
  >
  >nope that didn't work
  >  
  >  select test1.name_1 from test1 test2 where test1.code_1 = test2.code_2 \g
  >  ERROR:  attribute 'code_2' not found
  >
  >Umm... still no change.

junk=>  select * from test1, test2 where code_1 = test2.code_2 
junk-> ;
name_1|code_1|name_2|code_2
------+------+------+------
    10|     1|    11|     1
    11|     2|    11|     2
(2 rows)

junk=>  select test1.name_1 from test1, test2 where test1.code_1 = test2.code_2 ;
name_1
------
    10
    11
(2 rows)

You omitted the comma between the table names in the FROM clause.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
               PGP key from public servers; key ID 32B8FAA1
                 ========================================
     "For by grace are ye saved through faith; and that not
      of yourselves. It is the gift of God; not of works, 
      lest any man should boast."    Ephesians 2:8,9 





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~1998-11-17 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-11-17 16:05 How To Use JOIN? Takashi Tokunaga <taka-tok@chaos.digital-magic.co.jp>
1998-11-17 16:36 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1998-11-17 17:43 ` Oliver Elphick <olly@lfix.co.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox