| | |
I Need MySql Statement for this
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2007
Posts: 81
Reputation:
Solved Threads: 1
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.
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.
MySQL Syntax (Toggle Plain Text)
SELECT h.name FROM Human h, Attribute a, Human_Attribute ha WHERE h.human_id = ha.human_id AND a.attribute_id = ha.attribute_id AND a.attribute_id IN (list)
I NEED AN ADULT!
•
•
Join Date: May 2007
Posts: 81
Reputation:
Solved Threads: 1
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.
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.
•
•
Join Date: May 2007
Posts: 81
Reputation:
Solved Threads: 1
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.
![]() |
Similar Threads
- How to select the Last row from a table..using Mysql (MySQL)
- send email on mysql db update (PHP)
- Problem Using a Function Parameter in a MySQL Statement (Python)
- Converting MYSQL statement to MSSQL (MS SQL)
- MySQL LIKE statement (MySQL)
Other Threads in the MySQL Forum
- Previous Thread: Verifying Record before submitting to db
- Next Thread: insertion
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groupware hiring hyperic images innerjoins insert ip joebrockmeier join keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





