var sidebar_align = 'right';
var content_container_margin = parseInt('350px');
var sidebar_width = parseInt('330px');
Selecting data from two different tables in phpmyadmin
I have two tables,
A = Client table (client_id, client_name fields)
B = History table (amount field)
I want to select all clients from Client tables who have any record/amount in History Table.
Please let me know how to do this?
You should have an associated key for both tables. A: client_id, B:client_id
Antonis Adamakos @ FuzzFree :: Fully Managed Web Hosting, Development, Online Marketing
run this query in phpmyadmin
SELECT client.name,history.amount FROM HISTORY LEFT JOIN client ON client
.client_id = history.client_id
If there's always going to be a foreign key on 'client_id' between the tables you should use an INNER JOIN rather than a LEFT JOIN. The latter will also include rows which don't exist in both tables (a client without history rows, or orphaned history rows with no client).
Chief of R&D
, WebGroup Media LLC. -
is a fast and flexible web-based platform for business collaboration and automation.
It is always better to use a foreign key in table B if you dont have one there. Also use inner join ie (where a.id=b.fid) instead of left join to avoid unnecessary records.
You can run the sql query in phpmyadmin using the editSQL option
By jon31 in forum Programming Discussion
Last Post: 12-08-2005, 05:15 PM
By donnyboy in forum Hosting Security and Technology
Last Post: 09-09-2004, 07:03 AM
By null in forum Programming Discussion
Last Post: 09-02-2004, 09:21 PM
By HopelessLose in forum Programming Discussion
Last Post: 03-28-2004, 09:07 PM
By tonkagunner in forum Programming Discussion
Last Post: 09-06-2003, 10:31 PM