Extract from text id other table - PG 9.1

Started by Patrick Balmost 9 years ago3 messagesgeneral
Jump to latest
#1Patrick B
patrickbakerbr@gmail.com

Hi guys,

I've got tableA with 3 columns.

id(seriaL) | type(character varying(256)) | string(character varying(256))

I have the type/string value stored in another table, and from that i would
like to get the id.

Example:
http://dbfiddle.uk/?rdbms=postgres_9.6&fiddle=15c571caa36876f00a0a2eaace703a2b

How can I extract, from that tablea.type_m column the tableb.id value?

Thanks
Patrick

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Patrick B (#1)
Re: Extract from text id other table - PG 9.1

On Tuesday, June 6, 2017, Patrick B <patrickbakerbr@gmail.com> wrote:

I have the type/string value stored in another table, and from that i
would like to get the id.

JOIN ON (expression) ?

David J.

#3Jan de Visser
jan@de-visser.net
In reply to: Patrick B (#1)
Re: Extract from text id other table - PG 9.1

On Tuesday, June 6, 2017 10:32:16 PM EDT Patrick B wrote:

Hi guys,

I've got tableA with 3 columns.

id(seriaL) | type(character varying(256)) | string(character varying(256))

I have the type/string value stored in another table, and from that i would
like to get the id.

Example:
http://dbfiddle.uk/?rdbms=postgres_9.6&amp;fiddle=15c571caa36876f00a0a2eaace703a
2b

How can I extract, from that tablea.type_m column the tableb.id value?

SELECT b.id FROM tableb b, tablea a
WHERE (b.type || '/' || b.string = a.type_m) AND (a.id = 2);

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general