views:

153

answers:

2

How do I retrieve a multi-column PK in MySQL?

For example I have my primary key setup as PRIMARY KEY (donor_id,country_id)

Now if I want to get the primary key value without concatenating those 2 fields in a select query, how do I do that? I want to use this in a view (or better yet, directly in phpmaker).

+3  A: 

It's not clear what you mean by "without concatenating". A simple

SELECT donor_id, country_id FROM table WHERE ...;

will retrieve the records; you don't need to apply a CONCATENATE() function or anything like that. This is the Right Way to select two records from a table; the fact that they both happen to be declared part of the primary key changes nothing.

kquinn
+1  A: 

No special way is needed to get the records from table that has a multi-column PK in MySQL. Things might be different if you are using an ORM. An ORM may or may have special or different syntax/features for working with tables with multi-column PK.

mirnazim