PCHomepage
Programmer
I'm trying to create a query that pulls certain matches from a table but I can't seem to work out how to get what I need and I'm not even sure I can explain it! I know it can be done because there is an existing site using the same database set but it was written in compiled C and I do not have the original uncompiled C file from which it was created.
The problem is that all the keywords are in a single column and I need the text values of QEValue where KeyID matches that submitted but only when the IN ('C1BA','C1CA','C1EA') values also exist in QEValue, which they never do in the same row as the KeyID. These particular IN values are actually KeyID 28 so, of course, if I use KeyID 28, then I get results but it is not a list of values where KeyID=109 or whatever is submitted by a form. In fact, the list of values is built up using several selectors so the IN value list grows from selector to selector in the form. The point is to act as a filter
for finding a list of "files" only when it matches.
The data is in sets by FileID with only a few columns but a hundred or so rows for each FileID but only a single KeyID and QEValue value for each set. I didn't design the database and have no control over it so it is what it is. I'm not sure how to apply the SQL with the KeyID as the input and to give a list of values that match the input and only when the same FileID has the IN values since it's not using the FileID.
Here is a select statement that doesn't work but it might give a hint of what I'm trying to do. If you can make sense of this, any ideas?
The problem is that all the keywords are in a single column and I need the text values of QEValue where KeyID matches that submitted but only when the IN ('C1BA','C1CA','C1EA') values also exist in QEValue, which they never do in the same row as the KeyID. These particular IN values are actually KeyID 28 so, of course, if I use KeyID 28, then I get results but it is not a list of values where KeyID=109 or whatever is submitted by a form. In fact, the list of values is built up using several selectors so the IN value list grows from selector to selector in the form. The point is to act as a filter
for finding a list of "files" only when it matches.
The data is in sets by FileID with only a few columns but a hundred or so rows for each FileID but only a single KeyID and QEValue value for each set. I didn't design the database and have no control over it so it is what it is. I'm not sure how to apply the SQL with the KeyID as the input and to give a list of values that match the input and only when the same FileID has the IN values since it's not using the FileID.
Here is a select statement that doesn't work but it might give a hint of what I'm trying to do. If you can make sense of this, any ideas?
Code:
SELECT DISTINCT k.QEValue
FROM dcs_keys k
WHERE k.KeyID = 109
AND k.QEValue <> ''
AND k.QEValue IN
(SELECT QEValue FROM dcs_keys WHERE QEValue
IN ('C1BA','C1CA','C1EA'))
ORDER BY k.QEValue