Problem with multi tables in mysql

Links for php scripts

Moderators: egami, macek, gesf

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

Mon May 14, 2012 6:20 am


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


Antrikssh..... :)

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

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

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

Post Reply