Searching in 2 tables.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
/usr/local/
Forum Newbie
Posts: 9
Joined: Fri Mar 12, 2004 6:16 pm

Searching in 2 tables.

Post by /usr/local/ »

Hi,

I have 2 tables which are they students and users.

I have a form. That I am recording form details in students table.

student table includes
id - name - surname - email

When I approve students request, I copies from students table to users table.

users table includes same fields as students.

I can add add a field to students or users like status and giving them 0 or 1 data to checking it's approved or not. But I have a search page too, so I want to search it quickly, It would be lots of datas on students table.

Am I on right way?

My question is how can I make search on 2 tables in same time?

Thank you.
zenabi
Forum Commoner
Posts: 84
Joined: Mon Sep 08, 2003 5:26 am
Location: UK

Re: Searching in 2 tables.

Post by zenabi »

If both tables have the same fields then it will be wise to have just one table and do as you said:
I can add add a field to students or users like status and giving them 0 or 1 data to checking it's approved or not.
I don't understand this though:
But I have a search page too, so I want to search it quickly, It would be lots of datas on students table
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Search two tables at once:

Code: Select all

SELECT table.id, table.name, table2.id, table2.name FROM table, table2 WHERE table.id = '5' AND tablo.id = table2.id
But you would be best to use one table to store all the info as you suggest. Dont worry about having lots of entries in the table...it will still be fairly fast.
Post Reply