Hello. Created a database, created a query, everything is correct except for the output. The site asked why, they said that MySQL incorrectly handles USING. How to get rid of repeated fields. Is it unrealistic? Did this:

SELECT * FROM owners JOIN pets USING (owner_id); 

enter image description here

  • apparently this is really difficult - Muscled Boy
  • You specified Select *, so mysql brought you all the fields and owners.owner_id and pets.owner_id, which you see as duplicate. While I can only offer to explicitly indicate the fields that you need - Evgenii Izhboldin
  • mysql normally handles using. So, as it should be. What do you see "repeated field output" and why the data in your tables is not indicated in the question? - Shallow
  • @EvgeniiIzhboldin, yes you are right. After all, * displays all fields in this case, both tables. And yet, only explicitly specify? And whatever owner_id would you deduce from the owners or pets table once they are connected, it’s the same thing, but what is more correct (more correct) to write in the query? - Muscled Boy
  • @ Small, I'm sorry I didn’t write the data (I’m really dumb, I’m probably tired), but they are correctly displayed in the table, except for the formatting, since the last column went to front - Muscled Boy

2 answers 2

Try in the query instead of the JOIN write LEFT JOIN then there will be no duplicates

Addition

If it doesn't help, then this is the request.

 SELECT o.*, p.name, p.breed from owners o INNER JOIN pets p USING(owner_id); 

These are so-called aliases, one of their purposes, in order not to write the name of the entire table. Accordingly, "o" is an alias for the owners, and "p" is an alias for pets. Your last comment is correct.

  • write your answer completely please - Muscled Boy
  • You know it helped, but could you explain what o is, p I am just a beginner and not everything is clear to me. I understand that abbreviations of the tables or what? - Muscled Boy
  • So we display all the fields of the owners table and the name and breed of pets? - Muscled Boy
  • and if there were several tables starting with, oh, what would the alias be then? and generally how to understand what will be alias? - Muscled Boy
  • @MuscledBoy alias you invent yourself, it is important that it does not coincide with the reserved words - Jean-Claude

Try this

 SELECT owners.* FROM owners JOIN pets USING( owner_id) 
  • if we add pets.pet_id, pets.name, pets.breed to the parameters of owners. *, we get what we need - Muscled Boy