By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,446 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,446 IT Pros & Developers. It's quick & easy.

query with SQL UNION - help

P: n/a
I'm trying to get this to work, it will compile with "php -l" but the
search is broken. What's wrong? I have MYSQL 4.1. Thanks

$result = mysql_query("SELECT p.page_url AS url, p.title AS title,
p.descrip AS descrip, p.page_id AS id
FROM page p, word w, occurrence o
WHERE p.page_id = o.page_id AND
w.word_id = o.word_id AND
w.word_word LIKE '%$keyword%'")

UNION
(SELECT p.page_url AS url, p.title AS title,
p.descrip AS descrip, p.page_id AS id
FROM page p
WHERE p.descrip LIKE '%$keyword%'");

GROUP BY p.page_id
ORDER BY p.page_id DESC" );
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sun, 17 Oct 2004 20:18:39 GMT, leegold2 <le*****@nospam.net> wrote:
I'm trying to get this to work, it will compile with "php -l" but the
search is broken. What's wrong?


Define broken. Errors? (Which ones?) Wrong results? (What did you expect? What
data do you have?)

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
leegold2 wrote:
I'm trying to get this to work, it will compile with "php -l" but the
search is broken. What's wrong? I have MYSQL 4.1. Thanks

$result = mysql_query("SELECT p.page_url AS url, p.title AS title,
p.descrip AS descrip, p.page_id AS id
FROM page p, word w, occurrence o
WHERE p.page_id = o.page_id AND
w.word_id = o.word_id AND
w.word_word LIKE '%$keyword%'")

UNION
(SELECT p.page_url AS url, p.title AS title,
p.descrip AS descrip, p.page_id AS id
FROM page p
WHERE p.descrip LIKE '%$keyword%'");

GROUP BY p.page_id
ORDER BY p.page_id DESC" );


I can't remember which version of Mysql that unions are finally
supported. it may be that yours is too old.

However, will a variable name in single quoted in double quotes expand
to it's value? I don't think it will. You man need to catenate a few
substrings together to get it to work.

Steve
Jul 17 '05 #3

P: n/a
Steve wrote:
leegold2 wrote:
I'm trying to get this to work, it will compile with "php -l" but the
search is broken. What's wrong? I have MYSQL 4.1. Thanks

$result = mysql_query("SELECT p.page_url AS url, p.title AS title,
p.descrip AS descrip, p.page_id AS id
FROM page p, word w, occurrence o
WHERE p.page_id = o.page_id AND
w.word_id = o.word_id AND
w.word_word LIKE '%$keyword%'")

UNION
(SELECT p.page_url AS url, p.title AS title,
p.descrip AS descrip, p.page_id AS id
FROM page p
WHERE p.descrip LIKE '%$keyword%'");

GROUP BY p.page_id
ORDER BY p.page_id DESC" );

I can't remember which version of Mysql that unions are finally
supported. it may be that yours is too old.

the UNION statement is available in MySQL from version 4.0.0 onwards.
However, will a variable name in single quoted in double quotes expand
to it's value? I don't think it will. You man need to catenate a few
substrings together to get it to work. "LIKE '%$keyword%'" should work fine.

Steve

sadara
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.