I am trying to retrieve every data stored in 2 tabs from my database through a SELECT statement. The problem is there are a lot of columns in each tab and manually selecting each column would be a pain in the ass.
So naturally I thought about using a join :
select * from equipment
join data
on equipment.id = data.equipmentId
The problem is I am getting the equipment ID 2 times in the result. I thought that maybe some specific join could help me filter out the duplicate key, but I can't manage to find a way... Is there any way to filter out the foreign key or is there a better way to do the whole thing (I would rather not have to post process the data to manually remove those duplicate columns)?
CodePudding user response:
You can use USING clause.
"The USING clause specifies which columns to test for equality when two tables are joined. It can be used instead of an ON clause in the JOIN operations that have an explicit join clause."
select *
from test
join test2 using(id)
CodePudding user response:
You can also use NATURAL JOIN
select *
from test
natural join test2;