0

I'm developing a PHP application for querying a MySQL DB. My first query asks user to choice a value, that has a correspondence with the entry Sbj_ID in my table called 'Rec_SW2_Rel'. The value is correctly returned by the PHP function.

Now I have to query the table once again and perform following selection: imagine that the already chosen Sbj_ID is '9', I must return all the values of all those relations for which Rec_ID is equal and Position is = '2'.

Table 'Rec_SW2_Rel' looks like:

+ ---------------------------- +
* Rec_ID | Sbj_ID | Position | *
+ ---------------------------- +
*   10   |    9   |     1    | *
*   10   |  165   |     2    | *
*   10   |   23   |     3    | *
*   11   |    9   |     1    | *
*   11   |   15   |     2    | *
*   12   |   64   |     1    | *
*   12   |    8   |     2    | *
+ ---------------------------- +

Expected output should be:

10 | 165 | 2

11 | 15 | 2

1
  • 1
    What is Rec_ID equal to? Provide the first query to clarify. The way I read this is Sbj_ID is 9, so the output of Position should be 1. Commented Feb 10, 2014 at 9:18

1 Answer 1

1
select
*
from
your_table
where Position = 2 
and Rec_ID in (select Rec_ID from your_table where Sbj_ID = 9)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.