Problem with multi tables in mysql

Links for php scripts

Moderators: macek, egami, gesf

Post Reply
Antrikssh
New php-forum User
New php-forum User
Posts: 22
Joined: Wed May 02, 2012 5:27 am

Re: Problem with multi tables in mysql

Post by Antrikssh » Mon May 14, 2012 6:20 am

Hello,

If you don't mind then can you please tell me about the primary key of all this three tables. And which table is the master table.
If you are using same attributes name in all this three table along with different data then it has no use in my point of view, only one table is sufficient for that. It is very bad practice to create more than one table with same attribute in one database.

This will increase the problem of redundancy in the future. Suppose that according to your query if two table contain same type of information. I suggest you please try to remove the redundancy as much as possible...

Regards,

Antrikssh..... :)

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: Problem with multi tables in mysql

Post by Nullsig » Mon May 14, 2012 6:54 am

So your query is joining 3 tables together on without declaring how they are being joined together. So you are probably getting a CROSS JOIN effect on your results.

From the looks of your WHERE clause you are not assuming that any of the tables will always contain the data. As a result using something like OUTER or INNER joins will not work here.

I suggest you use UNIONS like this:

Code: Select all

SELECT *
FROM consignment c
WHERE c.consignment_no='" . mysql_real_escape_string($c) . "' && c.consignment = 'enable'
UNION
SELECT *
FROM h_consignment h
WHERE h.consignment_no='" . mysql_real_escape_string($c) . "' && h.consignment = 'enable'
UNION
SELECT *
FROM b_consignment b
WHERE b.consignment_no='" . mysql_real_escape_string($c) . "' && b.consignment = 'enable'

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests