Mysql syntax problem...

This is a discussion on "Mysql syntax problem..." within the Databases section. This forum, and the thread "Mysql syntax problem... are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 4th, 2006, 08:06
Up'n'Coming Member
Join Date: Sep 2005
Location: athens
Age: 26
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Mysql syntax problem...

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:

[tabel1rotein]
protein_id protein.name
1 PROTEIN_1
2 PROTEIN_2
3 PROTEIN_3
############################################
[table2rotein_reference]
protein_id[FK] reference_id[FK]
1 1
1 2
1 4
2 3
2 6
3 5
3 7
###############################################
[table3:reference]
reference_id datab_id[FK] code
1 1 AAAA
2 2 BBBB
3 2 CCCC
4 3 DDDD
5 1 EEEE
6 3 FFFF
7 1 GGGG
##############################################
[table4:database]
datab_id datab.name
1 Yale
2 Oxford
3 Cambridge
##############################################

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?
Reply With Quote

  #2 (permalink)  
Old Jan 6th, 2006, 15:51
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Mysql syntax problem...

I think you're looking for something like ...
Code: Select all
SELECT * from ((protein_reference join protein 
on protein_reference.protein_id = protein.protein_id) join reference 
on protein_reference.reference_id = reference.reference_id ) join database 
on reference.datab_id = database.datab_id 
where code = "AAAA"
which is basically translating your logic into SQL.
I would suggest that you do NOT call a table "database", by the way ...
You might also find this longer article that I wrote helpful.
Reply With Quote
Reply

Tags
mysql, syntax, problem

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP problem in Apache/PHP/MySQL JohnI PHP Forum 6 Aug 7th, 2008 10:26
[SOLVED] Syntax problem -- object has no properties dsmithhfx JavaScript Forum 6 Jan 19th, 2008 19:30
Php/Mysql Image Problem csun PHP Forum 11 Oct 27th, 2007 20:12
Syntax problem in PHP table creation masonbarge Databases 4 Jul 13th, 2006 22:27
PHP-MySQL problem robertboyle PHP Forum 4 Jun 16th, 2006 13:02


All times are GMT. The time now is 05:10.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43