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
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]
Link to comment
Share on other sites

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" ;
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[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!
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.