Groups > Databases > MySQL for ASP.NET > Re: How to link two tables together and limit the number of results retrieved from each?




How to link two tables together and limit the number of
results retrieved from each?

How to link two tables together and limit the number of results retrieved from each?
Tue, 18 Mar 2008 14:33:49 +000
Hello,

I have two tables which I want to link together using a foreign key and I'm
using a parameter in WHERE clause. I want to get all corresponding results from
the 1st table but only one results from the 2nd table. How can I accomplish
that?
Post Reply
Re: How to link two tables together and limit the number of results retrieved from each?
Tue, 18 Mar 2008 14:47:58 +000
Hi there,

 you can use JOIN for this purpose like in the following example:



SELECT Emps.Name, Orders.ProductName
FROM Emps
INNERJOIN Orders
ON Emps.Emp_ID=Orders.Emp_ID WHERE Emps.Emp_ID=1;

thanks
Post Reply
Re: How to link two tables together and limit the number of results retrieved from each?
Tue, 18 Mar 2008 15:04:38 +000
Thanks, but this query won't work in my case since I'm using a parameter which
is not a primary key for either of tables, but a column name which when used as
a parameter returns multiple records from both tables, and what I need is all
relevant records from 1st table but only the 1st relevant record from the 2nd
table.
Post Reply
about | contact