Gossamer Forum
Home : General : Databases and SQL :

Grabbing value from a different table, based on results from current table...

Quote Reply
Grabbing value from a different table, based on results from current table...
Hi guys, I'm trying to do something like;

SELECT pmtext.pmid FROM pm WHERE pm.userid = 3312

.. but its giving me an error.

Basically, I just want to select pmtext.pmid, based on the results for "WHERE pm.userid = ...".

Anyone got any ideas? My head is really hurting today Frown

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Grabbing value from a different table, based on results from current table... In reply to
Hi,

You need to join the tables:

select pmtext.pmid
from pm, pmtext
where pm.a = pmtext.b and
pm.userid = '....';

You need to look at how the tables are joined, and fill in the a and b. =)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Grabbing value from a different table, based on results from current table... In reply to
Thanks... worked a charm :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!