I Need MySql Statement for this

Reply

Join Date: May 2007
Posts: 81
Reputation: it2051229 is an unknown quantity at this point 
Solved Threads: 1
it2051229 it2051229 is offline Offline
Junior Poster in Training

I Need MySql Statement for this

 
0
  #1
Mar 30th, 2009
I have three tables in the mysql database. Let's say:

Table: Human -> Fields: human_id (primary key), name
Table: Attribute -> Fields: attribute_id (primary key), name
Table: Human_Attribute -> Fields: human_id (foreign key to human table), attribute_id (foreign key to attribute table)

Cardinality: Human Table to Human_Attribute Table (1 to Many)
Cardinality: Attribute Table to Human_Attribute Table (1 to Many)

My Objective is to search a Human given the attributes. So i created an interface where the user selects the attributes of the human and then given those attributes, I have to find humans that has those exact selected attributes.

Can anyone help me with the SQL statement for this? I know that basic queries won't work for this.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 146
Reputation: Stylish is an unknown quantity at this point 
Solved Threads: 14
Stylish's Avatar
Stylish Stylish is offline Offline
Junior Poster

Re: I Need MySql Statement for this

 
0
  #2
Mar 30th, 2009
  1. SELECT h.name
  2. FROM Human h, Attribute a, Human_Attribute ha
  3. WHERE h.human_id = ha.human_id AND a.attribute_id = ha.attribute_id AND a.attribute_id IN (list)
I NEED AN ADULT!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 81
Reputation: it2051229 is an unknown quantity at this point 
Solved Threads: 1
it2051229 it2051229 is offline Offline
Junior Poster in Training

Re: I Need MySql Statement for this

 
0
  #3
Mar 30th, 2009
hmm.. I have multiple attributes... what you have shown is for a single attribute only..

Here's what I want to happen, let's say I have a human named john with an attribute of head = 1, arms = 2, and legs = 2. John is stored in the human table and the head, arms, and legs are stored on the attributes table (note: head, arms, and legs are not table fields but values of the field called "attribute_name").

Now on the interface, I provided three textfields where to put the value of head, arms, and legs. So let's just say that the user entered 1 for head, 2 for arms, and 2 for legs... Now the queried result of course is John Because john has those specific attribute.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 146
Reputation: Stylish is an unknown quantity at this point 
Solved Threads: 14
Stylish's Avatar
Stylish Stylish is offline Offline
Junior Poster

Re: I Need MySql Statement for this

 
0
  #4
Mar 31st, 2009
I gave you the basics. Good luck.
I NEED AN ADULT!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 81
Reputation: it2051229 is an unknown quantity at this point 
Solved Threads: 1
it2051229 it2051229 is offline Offline
Junior Poster in Training

Re: I Need MySql Statement for this

 
0
  #5
Mar 31st, 2009
I already know the basics... what I need cannot be done by a basic sql query... that's why I have to go here and ask for help if it is possible or any other way that an advanced query can do that such as sub queries and stuff. But the problem is that my knowledge in SQL statement is not as far as a professional database administrator can do. I tried going to oracle but seems like it's not for free.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC