473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

query with SQL UNION - help

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
3 1932
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: techquest | last post by:
got slightly similar table. #Temp Table: name,name1,name2,exam,score A,A1,A21, A,A1,A21,math100,88 A,A1,A21,math101,56 A,A1,A21, A,A1,A21,math102,67 A,A1,A21, A,A1,A21,math104,45
7
by: angelasg | last post by:
Here is sample data I'm working with: ID ShiftDate SegTime 99 5/2/2005 5/2/2005 1:00:00 PM 99 5/2/2005 5/2/2005 1:04:00 PM 99 5/2/2005 5/2/2005 1:43:00 PM 99 5/2/2005...
15
by: plaztik8 | last post by:
Hello, Can someone please help me with a query? The table looks like this: BookedRooms =========== CustomerID RoomID BookDateID
3
by: Dalan | last post by:
From reading Access 97 help text, it seems that to do what I need to do will require a Union Query. As this would be my first, I think I might require a little guidance. I have two tables with...
1
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in...
4
by: spam | last post by:
If I run the following query in Access 2002 then I get the expected result: SELECT * FROM CSVImport UNION SELECT * FROM AssetTemp; I get the contents of both tables with no duplicates. If I...
5
by: BillCo | last post by:
I'm having a problem with a union query, two simple queries joined with a union statement. It's created in code based on parameters. Users were noticing some inconsistant data and when I analysed...
7
by: KoliPoki | last post by:
Hello every body. I have a small issue. Problem: I have a table with 4 descriptor columns (type). I need to formulate a query to retrieve a count for each type so I can group by...etc. The...
1
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form...
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.