Home > other >  SQL: Select a column where a longer string is like a column
SQL: Select a column where a longer string is like a column

Time:11-11

I want to change some data in the database where the text of a column is in a string.

For example we have the String: 'QWZ-$ §_REMARKIUFZQ'

Now I want to select a column where the column name has the text 'Mark'.

Something like this stupid try:

SELECT info FROM database WHERE '%' name '%' LIKE 'QWZ-$ §_REMARKIUFZQ'

Best Regards,

Christian

CodePudding user response:

From sqlite doc:

The operand to the right of the LIKE operator contains the pattern and the left hand operand contains the string to match against the pattern.

Switch the LIKE operands i.e. WHERE 'QWZ-$ §_REMARKIUFZQ' LIKE '%'||name||'%' (notice changed to sqlite concatenate operator || for native sqlite syntax).

Assuming sqlite3 version >= 3.16, you may find the table valued function pragma_table_info is the place to look.

CodePudding user response:

You really should elaborate what DB you are using: different databases have different metadata tables which contain such information, if I understood you correctly.

For example, ORACLE contains column information in the ALL_TAB_COLUMNS table, MySQL uses INFORMATION_SCHEMA.COLUMNS for the same purpose, etc.

Best Regards,

R

  • Related