Jump to content

very simple question (problem with select)


Gruzin

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/18800-very-simple-question-problem-with-select/
Share on other sites

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]
this seems to be the same issue as

http://www.phpfreaks.com/forums/index.php/topic,105805.0.html

post just above yours

$query = "SELECT * FROM 'test', 'test2' WHERE  'mes' LIKE '%$trimmed%' ORDER BY mes";

or to join both tables use


Select * FROM 'test1' NATURAL JOIN 'test2 WHERE 'mess' LIKE '%$trimmed%' ORDER BY mes" ;
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 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!
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.