Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this resolved by joins?

Status
Not open for further replies.

spamjim

Instructor
Joined
Mar 17, 2008
Messages
1,369
Location
US
I have a table with form submissions. The first column (s) is the submission identifier. The second column (d) is the field identifier in the form. The third column (data) is the value that was submitted.

Code:
s|d|data
1|1|2020-07-01
1|2|A
2|1|2020-07-01
2|2|B
3|1|2020-07-02
3|2|B
4|1|2020-07-04
4|2|A
5|1|2020-07-05
5|2|A

Is there a single query method where I can output the data from all records where the second field in the form = "A"?

Code:
s|data (field 2)|data (field 1)
1|A|2020-07-01
4|A|2020-07-04
5|A|2020-07-05
 
I think I resolved this as:

Code:
SELECT `s`, `data` FROM `table` 
WHERE `d` = 1 AND `s` IN (SELECT `s` FROM `table` WHERE `d` = 2 AND `data` = 'A')

This produces an acceptable:

Code:
s|data
1|2020-07-01
4|2020-07-04
5|2020-07-05
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top