MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 1st, 2005, 02:23 PM
pshy pshy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 4 pshy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 51 sec
Reputation Power: 0
Help with Join Query

Hi gang. I have searched and searched and cannot figure out what/why this query is wrong.

Code:
$query = "(SELECT * FROM table1 WHERE keywords LIKE '%".$term."%') UNION ALL (SELECT * FROM table2 WHERE keywords LIKE '%".$term."%')";


Table 1 and Table 2 are not relational. They are essentially two data storage tables. I want to search both to see if either match the related keyword (term). But my query fails. If I run each query by itself, it works fine.

Reply With Quote
  #2  
Old June 1st, 2005, 05:01 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
What do you mean 'fails'? Are you getting an error, or just unexpected result sets?
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
  #3  
Old June 2nd, 2005, 02:33 PM
pshy pshy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 4 pshy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 51 sec
Reputation Power: 0
Quote:
$result = mysql_query($query) or die("Could not execute Union search.");


I keep getting my 'die' results.

Reply With Quote
  #4  
Old June 2nd, 2005, 02:38 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
I'm guessing you're not selecting the same number of columns from each of your selects. Use this to get MySQL's error message; it'll give you a more specific idea of the problem.

PHP Code:
 $result mysql_query($query) or die("Could not execute Union search: " mysql_error()); 

Reply With Quote
  #5  
Old June 2nd, 2005, 02:56 PM
pshy pshy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 4 pshy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 51 sec
Reputation Power: 0
Great! You are correct. Ok I was doing a select *, so alternatively if I manually selected an equal number of columns, it should work.


Awesome, off to try it!

Reply With Quote
  #6  
Old June 6th, 2005, 12:29 PM
pshy pshy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 4 pshy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 51 sec
Reputation Power: 0
That was it. Thanks for the quick response/help.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Help with Join Query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway