Gruzin Posted August 27, 2006 Share Posted August 27, 2006 hi guys, I know that it sounds like funny, but I cann't select multiple tables from db. I've tryed some tutorials but... I have errors, if it won't take your time, please look at it and tell me what's the problem. here are some examples: [code]$query = "SELECT * FROM test OR test2 WHERE test LIKE '%$trimmed%' ORDER BY test";$query = "SELECT * FROM test AND test2 WHERE test LIKE '%$trimmed%' ORDER BY test";$query = "SELECT * FROM test, test2 WHERE test LIKE '%$trimmed%' ORDER BY test";[/code]Thanks for you time Quote Link to comment Share on other sites More sharing options...
Techbot Posted August 27, 2006 Share Posted August 27, 2006 I'm a noobie so excuse if I'm wrong but it might be because your fieldname is same as tablename.$query= "SELECT * FROM test,test2 where fieldname LIKE '%$trimmed%' ORDER BY fieldname " ;either way consider your post bumped :-\ Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 27, 2006 Author Share Posted August 27, 2006 I've tryed to change the fieldname but... Here is the eror:[code]$query = "SELECT * FROM test, test2 WHERE mes, mes LIKE '%$trimmed%' ORDER BY mes";[/code][color=red]You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' mes LIKE '%fun%' ORDER BY mes' at line 1[/color] Quote Link to comment Share on other sites More sharing options...
Techbot Posted August 27, 2006 Share Posted August 27, 2006 $query = "SELECT * FROM test, test2 WHERE mes LIKE '%$trimmed%' ORDER BY mes";ie not mes,mesassuming the field mes is in both tables. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 27, 2006 Author Share Posted August 27, 2006 yes u are right mes is in both tables, any ideas how to fix that? thanks for your help. Quote Link to comment Share on other sites More sharing options...
Techbot Posted August 27, 2006 Share Posted August 27, 2006 this seems to be the same issue as http://www.phpfreaks.com/forums/index.php/topic,105805.0.htmlpost just above yours$query = "SELECT * FROM 'test', 'test2' WHERE 'mes' LIKE '%$trimmed%' ORDER BY mes";or to join both tables useSelect * FROM 'test1' NATURAL JOIN 'test2 WHERE 'mess' LIKE '%$trimmed%' ORDER BY mes" ; Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 27, 2006 Author Share Posted August 27, 2006 I've got this:[color=red]Column: 'mes' in where clause is ambiguous[/color]what does it mean? Quote Link to comment Share on other sites More sharing options...
Techbot Posted August 27, 2006 Share Posted August 27, 2006 Ah sorry (I've only been at this a few days)it means because there are two fieldnames 'mes' it doesn't know which one to use to do the comparison.While you wait for someone more experienced than me to post, I suggest you stick with the NATUAL JOIN method. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 27, 2006 Author Share Posted August 27, 2006 [quote author=Techbot link=topic=105810.msg422883#msg422883 date=1156702871]Ah sorry (I've only been at this a few days)it means because there are two fieldnames 'mes' it doesn't know which one to use to do the comparison.While you wait for someone more experienced than me to post, I suggest you stick with the NATUAL JOIN method.[/quote]Thank u very much for your attention! Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 27, 2006 Author Share Posted August 27, 2006 how can I run query for each table? thanks again. Quote Link to comment Share on other sites More sharing options...
Gruzin Posted August 27, 2006 Author Share Posted August 27, 2006 Here, this code works for me but I've got another problem: ORDER BY doesn't work with it...Another question: can I limit the text displayed from row?[code]$query = "SELECT * FROM test WHERE mes LIKE '%$trimmed%' UNION SELECT * FROM test2 WHERE mes LIKE '%$trimmed%'";[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted August 28, 2006 Share Posted August 28, 2006 If you want to order the UNION, you'll have to wrap the whole thing in parentheses.. I don't know what you mean by "limit the text". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.