Im trying to select all column names from a mysql table that start with pweb and then have an integer.
This works for all column names:
SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_NAME`='producten';
But this does not work unfortunately, how can I make this happen?
SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_NAME`='producten' AND `COLUMN_NAME` LIKE `pweb`;
Thanks!
The reason for this is that the column names of these columns contained numbers and special characters at the beginning of the column name. The first two column names started with a number and hence the R programming language added the prefix X.
The reason I use SELECT COLUMN_NAMES is when using Stored Procedure, adding columns to the table will not screw your application. select * will give additional column (which you've just added to the table) and application will get additional column and may raise error.
If you have a list that contains two or more columns with similar names, you can get this error: Duplicate column name detected: List: "a list name", Internal column name: "a column name", SQL Column name: "a column name".
Try this
SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_NAME`='producten' AND `COLUMN_NAME` LIKE 'pweb%'
AND DATA_TYPE = 'int'
you have to add the % after pweb.
so the sql statement select all column_name which begins with pweb**
Note: ** means other caracteres
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA, COLUMNS
WHERE TABLE_NAME='producten' AND COLUMN_NAME LIKE 'pweb%';
Hope this help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With