我如何选择mySQL表中的特定行?
答案 0 :(得分:1)
通过引用与select中每个字段相关联的表来消除歧义通常是一种很好的形式。
然后你也引用了WHERE中的表:
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;
如果您希望应用程序的结果集中有更好的键名,您也可以为这些字段添加别名:
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;
答案 1 :(得分:0)
我认为person_id
是数字。
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
如果不是,请使用:
WHERE person.person_id = '102'