MySQL Search two tables

MySQL multiple parameter search through two tables

Page 1 of 1

5 Replies - 3359 Views - Last Post: 15 August 2010 - 02:41 AM

#1 freaky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-July 10

MySQL Search two tables

Posted 11 August 2010 - 11:06 AM

Hello all,

I have one problem to which i couldn't find the solution.
I have two MySQL tables...

lets say:

---------
table1
--------
id
name
text

--------
table2
--------
id
name
subtitle
text

Now they don't have same number of columns so I can't do Union.
Tables are not related (one is news, other is articles)
What I need to do?

User inputs search parameter for example: "test" (exclude ")
Then I need to search Table1.name, Table1.text AND Table2.name, Table2.subtitle, Table2.text
And output the results together.....

Do you have any sudgestions? :)
Thank you very much in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: MySQL Search two tables

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: MySQL Search two tables

Posted 12 August 2010 - 08:46 AM

Hi :)
Lets clear things up a bit. So you have the user to search the word test in two different, not connected tables? Right?
If yes, then you could use a variable(I guess you are using PHP) and with SELECT you'll assign the results from the first table. Then you can use another SELECT and concatenate the results to the same variable. Then use the variable as you wish in order to show the results.
Was This Post Helpful? 0
  • +
  • -

#3 freaky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-July 10

Re: MySQL Search two tables

Posted 13 August 2010 - 01:03 PM

View PostPennyBoki, on 12 August 2010 - 07:46 AM, said:

Hi :)
Lets clear things up a bit. So you have the user to search the word test in two different, not connected tables? Right?
If yes, then you could use a variable(I guess you are using PHP) and with SELECT you'll assign the results from the first table. Then you can use another SELECT and concatenate the results to the same variable. Then use the variable as you wish in order to show the results.


Yes you are correct, but let's say I want to see the resulty in phpMyAdmin. Is there a way to do this by union?join?something?

Thank you!
Was This Post Helpful? 0
  • +
  • -

#4 Somyagupta  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 85
  • Joined: 05-August 10

Re: MySQL Search two tables

Posted 13 August 2010 - 01:45 PM

Yes use join to combine the two table into one
Was This Post Helpful? 0
  • +
  • -

#5 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: MySQL Search two tables

Posted 13 August 2010 - 01:58 PM

Or you could CREATE VIEW so that you could select what you needed from the tables, without using extra memory. But still you need to join them somehow, maybe by id as in the following example:

LINK
Was This Post Helpful? 1
  • +
  • -

#6 freaky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 16-July 10

Re: MySQL Search two tables

Posted 15 August 2010 - 02:41 AM

thank you :) I understand everything =)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1