Duplicate internally linked columns

SELECT dealing_record.* ,shares.* ,transaction_type.* FROM shares INNER JOIN shares ON shares.share_ID = dealing_record.share_id INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id; 

The above SQL code gives the desired result, but with multiple repeating columns. In addition, with incomplete display of column headers. When i change

 linesize 100 

headers show, but the displayed data overlaps

I looked at similar questions, but it seems I don’t understand how to solve this.

+6
source share
2 answers

You have duplicate columns because you are querying the SQL server for the columns to display the same data (with SELECT dealing_record.* , Etc.) and then duplicate them.

For example, the column transaction_type.transaction_type_id and the column dealing_record.transaction_type_id will have corresponding rows (otherwise you will not see anything with INNER JOIN ), and you will see these duplicates.

If you want to avoid this problem or at least reduce the risk of duplicate results, improve your query using only the columns that you really need, as @ConradFrix already said. An example would be the following:

 SELECT dealing_record.Name ,shares.ID ,shares.Name ,transaction_type.Name ,transaction_type.ID FROM shares INNER JOIN shares ON shares.share_ID = dealing_record.share_id INNER JOIN transaction_type ON transaction_type.transaction_type_id = dealing_record.transaction_type_id; 
+8
source

Try joining stocks using deal_record rather than stocks again:

 select dealing_record.*, shares.*, transaction_type.* FROM shares inner join dealing_record on shares.share_ID = dealing_record.share_id inner join transaction_type on transaction_type.transaction_type_id= dealing_record.transaction_type_id; 
+1
source

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


All Articles