I tried looking everywhere but the only results id get is how to get the first 3 letters of a column's content, but that's not what I want. To make my point more clear I'll give an example: if there's a column called Employee_name and it had josh and Emily in it, I want to be able to get the first 3 letters of its name, which in this case would be Emp
Asked
Active
Viewed 49 times
1
-
do you need first 3 letters from column name or from the data in column. If only from column name is required then you have posted the content . – Amit Verma Jul 08 '21 at 09:32
-
1Would that help? https://stackoverflow.com/questions/4165195/mysql-query-to-get-column-names – ekochergin Jul 08 '21 at 09:33
-
Does this answer your question? [MySQL query column name substring](https://stackoverflow.com/questions/37655486/mysql-query-column-name-substring) – DevWithZachary Jul 08 '21 at 09:33
-
I need the first 3 letters from the column's name. again, if the column name is Employee I want to get Emp, I don't really care what data it holds. @AmitVerma – Rawan Ateya Jul 08 '21 at 09:34
-
yes, I think that's exactly what I'm looking for. Thank you both SO much! @ekochergin – Rawan Ateya Jul 08 '21 at 09:36
-
@Zachary ^ you too – Rawan Ateya Jul 08 '21 at 09:37
1 Answers
2
Maybe somethin like this?
SELECT SUBSTRING(`COLUMN_NAME`, 1, 3) AS col
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='your_db_name'
AND `TABLE_NAME`='your_table_name';

Ivan
- 76
- 7