A
A
Alexey Lebedev2015-06-04 14:04:07
MySQL
Alexey Lebedev, 2015-06-04 14:04:07

How to find a similar string in SQL?

There is such a table:
id param1 param2 param3....
1 1 1 1
2 1 1 1
3 1 1 1
4 2 1 1
5 2 1 1
It is necessary to return the following row by id=1 id=2,3
by id=4 return line id=5.
Of course, you can save all the params to an array and do this:

SELECT param1, param2, param3 FROM table WHERE id=1;
SELECT * FROM table WHERE [email protected] and [email protected] and [email protected];

But is there a more elegant solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeniy Odinets, 2015-06-04
@evgeniy2194

You can try to join the table on itself and compare CONCAT.
Didn't check but the logic is clear
Or:

SELECT * FROM table as a JOIN table as b ON a.param1 = b.param1  AND a.param2 = b.param2  AND a.param3 = b.param3 WHERE a.id = '1';

V
Vladimir Golubev, 2015-06-04
@wladyspb

SELECT * FROM table WHERE param1 = (SELECT param1 FROM table WHERE id=1) AND param2 = () ....
Also not the most elegant solution, really)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question