sckott
sckott

Reputation: 5913

Attach query string to results

When doing a sql query with something like

SELECT * FROM table1 WHERE column1 LIKE 'searchstring';

Is there a way to attach the query string, here 'searchstring' to the results? I ask because in this case

SELECT * FROM table1 WHERE column1 LIKE '%searchstring1%' OR column1 LIKE '%searchstring2%'; 

you can get multiple rows back in the result, and you may not know which rows go with which query string.

Is there a way to attach the query strings to their associated rows in another column? For example,

result_col1 result_col2     searched
a              b         searchstring1
c              d         searchstring1
f              g         searchstring2

Upvotes: 1

Views: 169

Answers (1)

Azmi Kamis
Azmi Kamis

Reputation: 901

You can include the searchstring as a column in your query and obtain them in your results:

SELECT 'searchstring' AS querystring, * FROM table1 WHERE column1 LIKE '%searchstring%';

Upvotes: 3

Related Questions