pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
regarding join
4+ messages / 4 participants
[nested] [flat]

* regarding join
@ 2006-03-25 06:36  AKHILESH GUPTA <akhilesh.davim@gmail.com>
  0 siblings, 3 replies; 4+ messages in thread

From: AKHILESH GUPTA @ 2006-03-25 06:36 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; pgsql-sql

hi all,
below I have created two tables in pgsql with field name as 'name' and 'id'
as their datatype 'varchar(15)' and 'integer'.

One of the table is:->
chemical=> select * from test1;
 name  | id
-------+----
 akhil |  1
 b     |  2
 c     |  3
 d     |  4
 e     |  5
 f     |  6
(6 rows)

Another table is:->
chemical=> select * from test3;
 name | id
------+----
 ab   |  1
 cd   |  2
 ef   |  3
 gh   |  4
(4 rows)

i want the output as:->
name  | id
-------+----
 akhil |  1 -----from test1 table
 ab   |  1------from test2 table
 b     |  2-----from test1 table
 cd   |  2------from test2 table
 c     |  3-----from test1 table
 ef   |  3------from test2 table
 d     |  4-----from test1 table
 gh   |  4------from test2 table
 e     |  5-----from test1 table
 f     |  6-----from test1 table

i have tried all the joins but it makes different fields for different
tables.
is there any way out for this kind of output??????????????????
(plz reply asap)urgent.

THANKS IN ADVANCE

--
Thanks & Regards,
Akhilesh
S/W Trainee (EDP),
NUCHEM Pvt. Ltd.,
Faridabad(Haryana)
GSM:-(+919891606064)

"FAILURES CAN BE FORGIVEN BUT AIMING LOW IS A CRIME"

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

* Re: regarding join
@ 2006-03-25 07:45  Andreas Kretschmer <akretschmer@spamfence.net>
  parent: AKHILESH GUPTA <akhilesh.davim@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Andreas Kretschmer @ 2006-03-25 07:45 UTC (permalink / raw)
  To: pgsql-sql

AKHILESH GUPTA <akhilesh.davim@gmail.com> schrieb:

> hi all,
> below I have created two tables in pgsql with field name as 'name' and 'id' as
> their datatype 'varchar(15)' and 'integer'.


> i want the output as:->

... a UNION of this 2 tables:

test=# select * from test1 union select * from test3 order by 2,1;
 name  | id
-------+----
 ab    |  1
 akhil |  1
 b     |  2
 cd    |  2
 c     |  3
 ef    |  3
 d     |  4
 gh    |  4
 e     |  5
 f     |  6
(10 rows)


HTH, Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°



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

* Re: regarding join
@ 2006-03-25 08:45  Martijn van Oosterhout <kleptog@svana.org>
  parent: AKHILESH GUPTA <akhilesh.davim@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Martijn van Oosterhout @ 2006-03-25 08:45 UTC (permalink / raw)
  To: AKHILESH GUPTA <akhilesh.davim@gmail.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql

On Sat, Mar 25, 2006 at 12:06:34PM +0530, AKHILESH GUPTA wrote:
> hi all,
> below I have created two tables in pgsql with field name as 'name' and 'id'
> as their datatype 'varchar(15)' and 'integer'.

<snip>

Looks like:

select * from test1
UNION ALL
select * from test3;

would be a very good start.
-- 
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachments:

  signature.asc (application/pgp-signature, 188B) download

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

* Re: regarding join
@ 2006-03-25 10:57  Stefan Becker <pgsql@yukonho.de>
  parent: AKHILESH GUPTA <akhilesh.davim@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Stefan Becker @ 2006-03-25 10:57 UTC (permalink / raw)
  To: pgsql-sql

given this.....
	 create table AA (id serial,name varchar(15));
	 create table BB (id serial,name varchar(15));
	insert into AA (name) values ('1243f');
	insert into AA (name) values ('asdfef');
	insert into AA (name) values ('fdbsfd');
	insert into AA (name) values ('btgrt');
	insert into AA (name) values ('crregsewf');
	insert into AA (name) values ('xedrgeef');
	insert into BB (name) values ('243f');
	insert into BB (name) values ('sdfef');
	insert into BB (name) values ('dbsfd');
	insert into BB (name) values ('tgrt');
	insert into BB (name) values ('rregsewf');
	insert into BB (name) values ('edrgeef');

you could try: (if you just need the one column "name")
	 select name from AA union select name from BB order by name;



a real nice way to go about this is:
	 create table CC (id serial,name varchar(15));
	 create table AA() inherits(CC);
	 create table BB() inherits(CC);
	insert into AA (name) values ('1243f');
	insert into AA (name) values ('asdfef');
	insert into AA (name) values ('fdbsfd');
	insert into AA (name) values ('btgrt');
	insert into AA (name) values ('crregsewf');
	insert into AA (name) values ('xedrgeef');
	insert into BB (name) values ('243f');
	insert into BB (name) values ('sdfef');
	insert into BB (name) values ('dbsfd');
	insert into BB (name) values ('tgrt');
	insert into BB (name) values ('rregsewf');
	insert into BB (name) values ('edrgeef');


=> select * from AA;
 id |   name
----+-----------
  1 | 1243f
  2 | asdfef
  3 | fdbsfd
  4 | btgrt
  5 | crregsewf
  6 | xedrgeef
(6 rows)

=> select * from BB;
 id |   name
----+----------
  7 | 243f
  8 | sdfef
  9 | dbsfd
 10 | tgrt
 11 | rregsewf
 12 | edrgeef
(6 rows)

=> select * from CC order by name;
 id |   name
----+-----------
  1 | 1243f
  7 | 243f
  2 | asdfef
  4 | btgrt
  5 | crregsewf
  9 | dbsfd
 12 | edrgeef
  3 | fdbsfd
 11 | rregsewf
  8 | sdfef
 10 | tgrt
  6 | xedrgeef
(12 rows)


by best regards,

Stefan


-- 
email: stefan@net-away.de
tel  : +49 (0)6232-629542 
       länger klingeln lassen (Weiterleitung aktiv)
fax  : +49 (0)6232-629544
http://www.net-away.de







Am Samstag, 25. März 2006 07:36 schrieb AKHILESH GUPTA:
> hi all,
> below I have created two tables in pgsql with field name as 'name' and 'id'
> as their datatype 'varchar(15)' and 'integer'.
>
> One of the table is:->
> chemical=> select * from test1;
>  name  | id
> -------+----
>  akhil |  1
>  b     |  2
>  c     |  3
>  d     |  4
>  e     |  5
>  f     |  6
> (6 rows)
>
> Another table is:->
> chemical=> select * from test3;
>  name | id
> ------+----
>  ab   |  1
>  cd   |  2
>  ef   |  3
>  gh   |  4
> (4 rows)
>
> i want the output as:->
> name  | id
> -------+----
>  akhil |  1 -----from test1 table
>  ab   |  1------from test2 table
>  b     |  2-----from test1 table
>  cd   |  2------from test2 table
>  c     |  3-----from test1 table
>  ef   |  3------from test2 table
>  d     |  4-----from test1 table
>  gh   |  4------from test2 table
>  e     |  5-----from test1 table
>  f     |  6-----from test1 table
>
> i have tried all the joins but it makes different fields for different
> tables.
> is there any way out for this kind of output??????????????????
> (plz reply asap)urgent.
>
> THANKS IN ADVANCE
>
> --
> Thanks & Regards,
> Akhilesh
> S/W Trainee (EDP),
> NUCHEM Pvt. Ltd.,
> Faridabad(Haryana)
> GSM:-(+919891606064)
>
> "FAILURES CAN BE FORGIVEN BUT AIMING LOW IS A CRIME"




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


end of thread, other threads:[~2006-03-25 10:57 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-25 06:36 regarding join AKHILESH GUPTA <akhilesh.davim@gmail.com>
2006-03-25 07:45 ` Andreas Kretschmer <akretschmer@spamfence.net>
2006-03-25 08:45 ` Martijn van Oosterhout <kleptog@svana.org>
2006-03-25 10:57 ` Stefan Becker <pgsql@yukonho.de>

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