pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hunter Hillegas <lists@lastonepicked.com>
To: PostgreSQL <pgsql-general@postgresql.org>
Subject: Query Help
Date: Tue, 23 Jul 2002 16:39:04 -0700
Message-ID: <B9633728.5B8D3%lists@lastonepicked.com> (raw)

I'm looking for a little query help, if anyone has a free moment...

I have two tables:

CREATE TABLE message_board_topics (
    rec_num integer NOT NULL PRIMARY KEY,
    topic_name varchar(255),
    topic_body text,
    topic_author varchar(20),
    topic_author_email varchar(50),
    topic_date date,
    topic_updated datetime,
    number_of_comments integer
);

CREATE TABLE message_board_comments (
    rec_num integer NOT NULL PRIMARY KEY,
    topic_id integer REFERENCES message_board_topics,
    comment_parent integer,
    comment_name varchar(255),
    comment_body text,
    comment_author varchar(20),
    comment_author_email varchar(50),
    comment_date date
);

Anyway, I want to do a quick and dirty search against them... Basically I
want to find any message_board_topic where the submitted text matches either
the topic_name, topic_body, topic_author, or the comment_author of any
related comment...

I tried this:

SELECT * FROM message_board_topics, message_board_comments WHERE
upper(topic_name) LIKE upper('%test%') OR upper(topic_body) LIKE
upper('%test%') OR upper(topic_author) LIKE upper('%test%') OR
(upper(message_board_comments.comment_author) LIKE upper('%test%') AND
message_board_comments.topic_id = message_board_topics.rec_num) ORDER BY
message_board_topics.rec_num DESC;

Now, this returns no rows but this query that doesn't search the comments
table returns a row:

SELECT * FROM message_board_topics WHERE upper(topic_name) LIKE
upper('%test%') OR upper(topic_body) LIKE upper('%test%') OR
upper(topic_author) LIKE upper('%test%') ORDER BY
message_board_topics.rec_num DESC;

Any ideas what I am doing wrong? It would be a big help.

Thanks,
Hunter




view thread (70+ messages)  latest in thread

Message-ID: <B9633728.5B8D3%lists@lastonepicked.com>
Permalink:  ../B9633728.5B8D3%25lists@lastonepicked.com/
Also on:    postgresql.org/message-id/B9633728.5B8D3%lists@lastonepicked.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: lists@lastonepicked.com
  Subject: Re: Query Help
  In-Reply-To: <B9633728.5B8D3%lists@lastonepicked.com>
  References: <B9633728.5B8D3%lists@lastonepicked.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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