MySQL joins 2 tables, but renames columns because they have the same name

I have 2 tables,

admin, price

  • admin contains columns (id, date_created, type, value)
  • Pricing contains columns (id, date_created, relation, value)

I want to make a choice that joins two tables, where pricing.relation = admin.id

How to rename values, id and date_created strings so that they do not overwrite each other?

That's what I'm doing:

$sub_types = $database->query(' SELECT pricing.*, admin.* FROM pricing, admin WHERE pricing.relation = admin.id '); 
+4
source share
1 answer

You can use aliases:

 SELECT p.id as pid, p.date_created as pricing_date, p.type, p.value as pricing_value, a.id as aid, a.date_created as admin_date, a.relation, a.value as admin_value FROM pricing p inner join admin a on p.relation = a.id 
+9
source

Source: https://habr.com/ru/post/1439371/


All Articles