I have 2 tables. tbl_names
and tbl_section
which has both the id
field in them. How do I go about selecting the id
field,
The simplest solution is a join with USING
instead of ON
. That way, the database "knows" that both id
columns are actually the same, and won't nitpick on that:
SELECT id, name, section
FROM tbl_names
JOIN tbl_section USING (id)
If id
is the only common column name in tbl_names
and tbl_section
, you can even use a NATURAL JOIN
:
SELECT id, name, section
FROM tbl_names
NATURAL JOIN tbl_section
See also: https://dev.mysql.com/doc/refman/5.7/en/join.html