vendredi 19 février 2016

updating a column with same values

I have a table named FIELDS which has a column named value, I have another table named SETTINGS which has a column named property and another column named state.

In SETTINGS the property column contains a string like

state_value
doc_state_value

Where the value after the underscore is similar to the value stored in the FIELDS column.

The state column has integer values 0,1

I want to fetch all rows from FIELDS whose values are present in the property column in SETTINGS and the corresponding value is 0,

To fetch from SETTINGS table I can easily write

SELECT property FROM SETTINGS WHERE property LIKE '%state%' and state='0'

This may return me a single row or multiple rows

This rows will be like this now,

state_value1
state_value2
state_value3

Now I want to check whether my value column form FIELD is contained in any of these strings or not

I have tried

value IN(SELECT property FROM SETTINGS WHERE property LIKE '%state%' and state='0')

I have also tried nesting it like this

value IN(value LIKE(SELECT property FROM SETTINGS WHERE property LIKE '%state%' and state='0'))

For example if my FIELDS table has a entry in value column as '1234'

and my SETTINGS table has a entry for property 'state_1234' and state is '0' I will have to fetch this column form FIELDS

Aucun commentaire:

Enregistrer un commentaire