D
D
Daniel2019-02-12 17:12:57
MySQL
Daniel, 2019-02-12 17:12:57

How to display a column name by its number in MySQL using only SQL?

I need to create a trigger for a table that should compare cell values ​​in a row from left to right starting from cell 5 and up to n
The problem is that the name of all columns after the fifth is absolutely unknown, they are created dynamically. (And their number is always different, maybe two or maybe 100).
To solve this problem, I ask the question (in the title)
P.s. I know how to do it through PHP, C, C ++, but the table will be accessed using two completely different interfaces, and therefore I would like to avoid copying the code. And make a completely universal solution.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2019-02-12
@Porohovnik

SELECT ORDINAL_POSITION, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTable'

O
Oleg, 2019-02-12
@402d

show FIELDS FROM
https://dev.mysql.com/doc/refman/8.0/en/show-colum...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question