Reputation: 73
How would I go about selecting a specific row in a mySQL table?
Upvotes: 0
Views: 41
Reputation: 71384
It's generally good form to remove ambiguity by referencing the table associated with every field in the select.
Then you also reference the table in the WHERE as well:
SELECT
person.person_id,
person.last_name,
patient.date_registered /* I am assuming this is value from patient table */
FROM person
INNER JOIN patient
ON person.person_id=patient.patient_id
WHERE person.person_id = 102;
You can also alias the fields if you want better key names in the result set for your application:
SELECT
person.person_id AS `person_id`,
person.last_name AS `last_name`,
patient.date_registered AS `date_registered`
FROM person
INNER JOIN patient
ON person.person_id=patient.patient_id
WHERE person.person_id = 102;
Upvotes: 1
Reputation: 33381
I assume that the person_id
is numeric.
SELECT person.person_id, last_name, date_registered
FROM person
INNER JOIN patient
ON person.person_id=patient.patient_id;
WHERE person.person_id = 102
if no, use:
WHERE person.person_id = '102'
Upvotes: 0