Forum Moderators: open

Message Too Old, No Replies

Mysql syntax difficulty

         

ktsirig

9:03 am on Jan 4, 2006 (gmt 0)

10+ Year Member



Hi everybody and Happy New Year!
I have been dealing with this problem of my biology class lesson since yesterday,
I believe it's some silly mistake I am making.
I have these tables:

[tabel1:protein]
protein_idprotein.name
1PROTEIN_1
2PROTEIN_2
3PROTEIN_3
############################################
[table2:protein_reference]
protein_id[FK]reference_id[FK]
11
12
14
23
26
35
37
###############################################
[table3:reference]
reference_iddatab_id[FK]code
11AAAA
22BBBB
32CCCC
43DDDD
51EEEE
63FFFF
71GGGG
##############################################
[table4:database]
datab_iddatab.name
1Yale
2Oxford
3Cambridge
##############################################

If the user gives me code AAAA as input,
I want to write an SQL statement that will retrieve all the other codes from table3
and all datab.name from table4 that belong to the same protein,
that is: BBBB[+Oxford], DDDD[+Cambridge].

I hope it is not confusing..
The course that SQL must follow is:
STEP1: Code AAAA is given from user
STEP2: go to table2 and see(using reference_id) that protein_id#1 has also reference_id#2 +reference_id#4
STEP3: go to table3 and see which datab_id are placed in codes BBBB + DDDD
STEP4: go to table4 and see (using datab.name) that the reffering databases are those of Oxford(datab_id#2)
and Cambridge(datab_id#3)
STEP5: print => BBBB[Oxford]
DDDD[Cambridge]

Any help?

FalseDawn

1:03 am on Jan 5, 2006 (gmt 0)

10+ Year Member



Something like:
SELECT T3.code,T4.datab.Name FROM
(((table3 T3 INNER JOIN table2 T2 ON T3.reference_id=T2.protein_id)
INNER JOIN T3 ON T2.reference_id=T3.reference_id)
INNER JOIN table4 T4 ON T3.datab_id=T4.datab.name)
WHERE T3.code='AAAA'

might be adjusted to work - I don't think this will work as-is - probably need a DISTINCT in there, and it will also return your original "AAAA" links...