Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make sql subqueries stop complaining about duplicate columns

Tags:

sql

php

mysql

so suppose I have this query

SELECT COUNT(*) FROM (SELECT * FROM k JOIN j ON k.id = j.aid) k 

suppose k and j have two columns with the same name, this entire query will complain with the duplicate columns error....

while simply executing SELECT * FROM k JOIN j ON k.id = j.aid will execute just fine despite the duplicate columns....

I know that you can use USING in the subquery to specify which column to use in case of duplicates, but is there a way to specify the query so that it'll automatically pic a specific column (whether randomly or using whatever rule) to use in case of duplicates without me having to manually specify them?

ie do this without modifying the subquery (SELECT * FROM k etc) and only modify the superquery (SELECT COUNT(*) FROM...) and make it as abstract as possible so that it'll work regardless of what the subquery is

like image 226
kamikaze_pilot Avatar asked May 13 '26 20:05

kamikaze_pilot


1 Answers

No.

The simplest solution in this example would be to replace * with 1 in the subquery. Is the replacement of a single character really so problematic?