query help

Started by G.L. Grobeover 24 years ago3 messagesgeneral
Jump to latest
#1G.L. Grobe
gary@grobe.net

Hi all,

How would I get TableB.label if all I know about is TableA.name?

I was thinking about a query on TableA first, then within the while
(rs.next()), I'd do another query using the result set from A on B, but I
don't like that much, and it seems kind of slow.

Any help much appreciated!

TableA
idA | name | class
-----------------
11 test1 1
12 test2 1
13 test3 2
14 test4 2

TableB
idB | idA | label
----------------
1 11 nameA
2 12 nameB
3 13 nameC
4 14 nameD

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: G.L. Grobe (#1)
Re: query help

Maybe this?
select label from TableB, TableA
where TableB.idA=TableA.idA
and TableA.name=<whatever>

On Thu, 30 Aug 2001, G.L. Grobe wrote:

Show quoted text

Hi all,

How would I get TableB.label if all I know about is TableA.name?

I was thinking about a query on TableA first, then within the while
(rs.next()), I'd do another query using the result set from A on B, but I
don't like that much, and it seems kind of slow.

Any help much appreciated!

TableA
idA | name | class
-----------------
11 test1 1
12 test2 1
13 test3 2
14 test4 2

TableB
idB | idA | label
----------------
1 11 nameA
2 12 nameB
3 13 nameC
4 14 nameD

#3Noname
wsheldah@lexmark.com
In reply to: Stephan Szabo (#2)
Re: query help

For one specific label:
select TableB.label from TableA, TableB where TableA.idA=TableB.idA and
TableA.name='test2';

To get a list of name-label pairs:
select TableA.name, TableB.label from TableA, TableB where TableA.idA=TableB.idA
order by TableA.name, TableB.label;

"G.L. Grobe" <gary%grobe.net@interlock.lexmark.com> on 08/30/2001 07:45:20 PM

To: pgsql-general%postgresql.org@interlock.lexmark.com
cc: (bcc: Wesley Sheldahl/Lex/Lexmark)
Subject: [GENERAL] query help

Hi all,

How would I get TableB.label if all I know about is TableA.name?

I was thinking about a query on TableA first, then within the while
(rs.next()), I'd do another query using the result set from A on B, but I
don't like that much, and it seems kind of slow.

Any help much appreciated!

TableA
idA | name | class
-----------------
11 test1 1
12 test2 1
13 test3 2
14 test4 2

TableB
idB | idA | label
----------------
1 11 nameA
2 12 nameB
3 13 nameC
4 14 nameD

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)