| | |
Question about SELECT statement.
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2005
Posts: 92
Reputation:
Solved Threads: 0
I have three tables.
table1:
|-------|-----------|
| Name | Studyarea |
|------|-----------|
| Joe | 1 |
| Joe | 2 |
| Chris | 1 |
| Mike | 3 |
|-------|----------|
table2:
|-----------|-----------|
| Studyarea | CourseID |
|-----------|-----------|
| 1 | 1,2 |
| 2 | 2 |
| 3 | 2,3 |
|-----------|-----------|
table3:
|-----------|-------------|
| CourseID | Course Name |
|-----------|-------------|
| 1 | Hardware |
| 2 | Programming |
| 3 | Networking |
|-----------|-------------|
I am kind of confused how I can write statement in Mysql to list each student name with the course name, like:
Joe--Hardware
Joe--Programming
Chris--Hardware
Mike--Networking
In table2, the courseID is in format of contactnated string.
Need help, thanks in advance.
table1:
|-------|-----------|
| Name | Studyarea |
|------|-----------|
| Joe | 1 |
| Joe | 2 |
| Chris | 1 |
| Mike | 3 |
|-------|----------|
table2:
|-----------|-----------|
| Studyarea | CourseID |
|-----------|-----------|
| 1 | 1,2 |
| 2 | 2 |
| 3 | 2,3 |
|-----------|-----------|
table3:
|-----------|-------------|
| CourseID | Course Name |
|-----------|-------------|
| 1 | Hardware |
| 2 | Programming |
| 3 | Networking |
|-----------|-------------|
I am kind of confused how I can write statement in Mysql to list each student name with the course name, like:
Joe--Hardware
Joe--Programming
Chris--Hardware
Mike--Networking
In table2, the courseID is in format of contactnated string.
Need help, thanks in advance.
Your data isn't correct. In table2, you have multiple IDs in some of the rows: This is incorrect. Each row should only have one ID per column. If a Studyarea has more than one CourseID, then there will be more than one row with that Studyarea: Now you can leave the IDs as concatinated strings, but that breaks database design and requires more work. What you would have to do is use a query to merge the table1 and table2 data, split the values out of the CourseID values, and execute additional queries. I can't see anyone designing a database this way unless they had no idea what they were doing. Is there a reason why you want it to be this way?
P.S. Use code tags ([code][/code]) so that your data looks nice. It's hard to look at your data when it doesn't line up.
MySQL Syntax (Toggle Plain Text)
table2: |-----------|-----------| | Studyarea | CourseID | |-----------|-----------| | 1 | 1,2 | | 2 | 2 | | 3 | 2,3 | |-----------|-----------|
MySQL Syntax (Toggle Plain Text)
table2: |-----------|-----------| | Studyarea | CourseID | |-----------|-----------| | 1 | 1 | | 1 | 2 | | 2 | 2 | | 3 | 2 | | 3 | 3 | |-----------|-----------|
P.S. Use code tags ([code][/code]) so that your data looks nice. It's hard to look at your data when it doesn't line up.
Did we help you? Did we miss the point entirely? Update your thread and let us know.
Don't like the answers you are getting?
Did you try searching?
Clean up and optimize Windows 2000/XP
Don't like the answers you are getting?
Did you try searching?
Clean up and optimize Windows 2000/XP
![]() |
Similar Threads
- Question about SELECT statement (MS SQL)
- Hi,Need help on sql select statement structure (MS SQL)
- Question about select statement (MySQL)
- Question about SELECT statement (MySQL)
- select statemt LIKE (MySQL)
- Getting current value in Select Statement (MS SQL)
- Program Problem with a select statement to access Data base (C)
Other Threads in the MySQL Forum
- Previous Thread: can i select the 2nd row/record from a table
- Next Thread: Error message
Views: 1926 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for MySQL
"use" 1 agplv3 alfresco amazon api artisticlicense breathalyzer camparingtocolumns changingprices cmg contentmanagement count court crm data database design developer development drupal dui ec2 eliminate email enter enterprise error eudora facebook form foss gartner gnu gpl greenit groklaw groupware images innerjoins insert ip joebrockmeier join journalism keywords laptop law legal license licensing linux maintenance managing matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource operand oracle pdf penelope php priceupdating referencedesign remove reorderingcolumns results resultset saas select sharepoint sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency update virtualization





