V
V
Vangor2014-03-14 20:39:04
SQL
Vangor, 2014-03-14 20:39:04

How to implement a selection from the database by parameters?

It is necessary to implement a selection from the table
The table has the structure
id | tmplvarid | contentid | value
1 | 23 | 14 | Decompressor
2 | 22 | 15 | 50
3 | 22 | 16 | 51
4 | 34 | 17 | Decompressor2
tmplvarid is an object that can have different values ​​in each contentid
The task is to select all contentid values ​​that match 3 parameters and one range.
Those. for example, you need to select all contentid that lie in the range from 45 to 60, and at the same time equal tmplvarid = 22, plus have tmplvarid = 14 a value of which should have the value "Decompressor"
I know that the task is solved by means of Self Join and\or subqueries. But I can't figure out how

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Khirenko, 2014-03-15
@Satanpit

Amm... what for nested requests and JOIN?
Based on your description, you get something like:

SELECT contentid 
FROM `table` 
WHERE tmplvarid = 22 AND value = 'Декопрессор' AND contentid BETWEEN 45 AND 60

S
svd71, 2014-03-15
@svd71

Let's tweak @Satanpit a bit :

SELECT contentid 
FROM `table` 
WHERE (tmplvarid = 22 or tmplvarid =14) AND value LIKE 'Декопрессор%' AND contentid BETWEEN 45 AND 60

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question