I have a rather long SQL (MySQL flavor) query and want to check if different fields queries have the same name (or alias) like SELECT a, a .... Any software for this?

I use Linux.

  • Just curios. Is this a major problem? If you intend to display it, the duplication will be immediately visually apparent. If not, then it doesn’t matter whether the code access field a the identical value from the other field a? Obviously, you had a problem, or you wouldn't ask. Personally, I don’t see the need for a tool, but, if you want one, that’s fine. Other than a (minor, IMO) performance hit, is this a big thing, which I am unaware of? I am a causal MySql user & always keen to learn – Mawg says reinstate Monica Mar 3 '17 at 8:48
  • 1
    @Mawg I have solved the problem simply highlighting a word in a text editor. All duplicates are highlighted by a feature of the editor. This solves the problem for me. – porton Mar 4 '17 at 16:29
  • 1
    @Mawg The essence of the problem was not to create a Perl code with messed field names, when two fields are assigned by the same name, so damaging the logic of my program – porton Mar 4 '17 at 16:30

No software needed. Create a dummy view using your query. If it works, you're good, because views don't support multiple columns with the same name.

CREATE VIEW v1 AS SELECT ... ...your query. If there are duplicate column names, this fails... and gives you one of the duplicate names.

ERROR 1060 (42S21): Duplicate column name 'foo'

Note also that if you have a client library that understands it, a SELECT query returning multiple columns with the same name is not technically invalid in MySQL, which is why such a query doesn't throw an error if you simply execute it. Not a good thing to do, typically, but not technically invalid.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.