P
P
Petrify2011-07-29 08:27:08
SQL
Petrify, 2011-07-29 08:27:08

Prompt with sql query

There is a query in the form of
SELECT value FROM table WHERE value2 in ('1','2','3','1')

how to make rows output according to the number of duplicates in case of duplicate values ​​in the in operator argument?
Those.
if a table of type

value value2
1 1
2 2
3 3

would output
value
1
2
3
1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fastto, 2011-07-29
@Fastto

Because is the result of another query, then the solution is:
SELECT YOUR_TABLE.value
FROM ( SELECT value FROM… bla bla ) AS tbl < - here is your second query
LEFT JOIN YOUR_TABLE ON YOUR_TABLE.value2 = tbl.value
( SELECT value FROM… bla bla ) - there should be a query that returns the list you need in the value column

T
Tonik, 2011-07-29
@Tonik

As far as I remember, using IN is not possible. It immediately comes to mind to make a temporary table from one column, insert all the values ​​from IN there and then rewrite the query for what type
SELECT value
FROM table t
JOIN tmp_tabel t2 ON (t.value2 = t2.value)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question