Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 8E4B26333FE for ; Sat, 9 Jan 2010 05:07:42 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 34245-09 for ; Sat, 9 Jan 2010 09:07:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pz0-f201.google.com (mail-pz0-f201.google.com [209.85.222.201]) by mail.postgresql.org (Postfix) with ESMTP id 9CFB26329CA for ; Sat, 9 Jan 2010 05:07:30 -0400 (AST) Received: by pzk39 with SMTP id 39so1677309pzk.15 for ; Sat, 09 Jan 2010 01:07:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Ci4t4JQMfAqDlePTP8lOsBsgiSR3EQYUw1o7bl9sjQA=; b=Qk+rSlbB7VCIUHLjUnX+k175cT6kIOfcWpTVWLAkR6Rl3kc99o3l4LFJNGjZUB61O9 v4J0TuM4qxNLMggsLyWkVwMEzDqdu7AGEX26KIYfLDRAtXdlXW+mC0yFh6TY40sbUL8I L3rsOXqV7Wb7OCOjKGh53p4ncO6Mcz1+qvlu8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=JwMgxkv7+zBEuaZBaTip2TQmISxWePDQhyxOIQTEVwq7mlvxxWRV+QmGKQdwrWEQhz F6+uXgBNQKi0uyEH9E4q4+QWxQt9S1LQmuG8p82YsJAq9RzeKlWr4O8dHOpcVCcCeLXd KWg5axDr1tI7Dgj6oMmHD0GSiR+c5Xu9V8bko= MIME-Version: 1.0 Received: by 10.114.7.10 with SMTP id 10mr1419608wag.90.1263028048859; Sat, 09 Jan 2010 01:07:28 -0800 (PST) In-Reply-To: <533df7fa1001082026h53b5d897x2fc1fa2a6f7ff6df@mail.gmail.com> References: <533df7fa1001082026h53b5d897x2fc1fa2a6f7ff6df@mail.gmail.com> Date: Sat, 9 Jan 2010 18:07:28 +0900 Message-ID: <1d581afe1001090107j7ace3eedm197d12b50579be58@mail.gmail.com> Subject: Re: how to do this query From: Ian Barwick To: Wes James Cc: pgsql-sql@postgresql.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.855 tagged_above=-10 required=5 tests=AWL=0.745, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/12 X-Sequence-Number: 33548 2010/1/9 Wes James : > I have two tables: > > students > =C2=A0stu_name > =C2=A0schols_selected > > scholarships > =C2=A0schol_name > =C2=A0short_name > > schols_selected is made up of scholarships the students have selected, > the field content will look like schol1:schol2:schol3 > > I need a select that does something like this > > select schol_name, short_name, stu_name, schols_selected > from scholarships, students > where short_name is in schols_selected > > I have tried: > > where short_name like '%' || schols_selected || '%' > > but i'm not sure how to include a field result in between like operators. Theoretically this construction is correct, but as the LIKE pattern is probably longer than the contents of the field you are operating on, it won't work in the way you intend it to. > how do I get a list of scholarships based one which student selected > it where the selected result is a string of colon seperated options? I'm not quite sure what you mean here, but in order to be able to match scholarships selected to an individual student given your table structure, you could try turning the fields round, e.g. WHERE schols_selected LIKE '%' || short_name || '%' However this is a lousy way of doing things and will cause performance problems with a non-trivial amount of data. (An additional table is what would would help you here). HTH Ian Barwick