HRMNS
HRMNS

Reputation: 60

Check value in row mysql

I have structure of table like this

id  1   2   3   4   5   6   7   8   9   10  11  ..... till  50 or 60
1   A   B   C   D   E   F   G   H   I    J   K
2   G   H   A   B   C   D   L   M   N    O   P
3   So on .. 

Now i want to find whether there is value G in first row . Help !

Upvotes: 1

Views: 474

Answers (2)

Firoz Ansari
Firoz Ansari

Reputation: 2515

Isn't your structure should look like this:

ValueMatrix Struc
----------------------
row_id      INT
column_id   INT
value       VARCHAR(1)

And entered data like this:

ValueMatrix Data
----------------------
row_id      column_id   value
1           1           A
1           2           B
1           3           C
2           1           G
2           2           H
2           3           A

And so query to retrieve value G:

SELECT *
FROM ValueMatrix
WHERE row_id = 1 AND value='G'

Upvotes: 0

Rawkode
Rawkode

Reputation: 22592

You could use CONCAT. I believe something like this is what you're after?

SELECT id FROM table WHERE CONCAT(1,2,3,4,5,6......50) LIKE '%G%';

SELECT id, LOCATE('G', CONCAT(1,2,3,4,5,6......50)) FROM table WHERE CONCAT(1,2,3,4,5,6......50) LIKE '%G%';

Upvotes: 2

Related Questions