473,379 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Bridge table in mySQL

sunsolaris2000
I have 2 tables:
professors(professor_id INT PK, name VARCHAR), courses(course_id INT PK, title).
I also have a bridge table: professors_courses(prof_id INT FK, course_id INT FK).

I still didn't find a query for something like this:
given the professor name, "x"

Using the bridge table, find all the courses for professor X.

**professors**
Expand|Select|Wrap|Line Numbers
  1. prof_id | name
  2.    1      John
**professors_courses**
Expand|Select|Wrap|Line Numbers
  1. prof_id | course_id
  2.    1         2
  3.    1         3
  4.    1         5
  5.    2         1
**courses**
Expand|Select|Wrap|Line Numbers
  1. course_id | title
  2.     1      English 
  3.     2      French
  4.     3      Italian
  5.     4      Japanese
  6.     5      Polish
Given the name "John", seems he has the following courses: French,Italian,Polish
Jul 26 '12 #1
2 5832
Rabbit
12,516 Expert Mod 8TB
Join all the tables together and filter for the professor's name in the where clause.
Jul 26 '12 #2
Well finally I did:

Expand|Select|Wrap|Line Numbers
  1. String sqlQuery = "SELECT courses.title FROM courses INNER JOIN professors_courses ON professors_courses.course_id = course.course_id WHERE prof_id = '"+x+"'";
User will choose a professor and I find out his id and assert his id in x.

Thank you for your time anyway :)
Jul 27 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Babs Patel | last post by:
I'm new to database design, but I understand the basics of MySQL and php. To make a simple music database in MySQL, I've made a table of songs (song) and a table of players (player) joined by a...
6
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
1
by: Agathe | last post by:
Bonjour, Je souhaite insérer dans une table MySQL des données provenant d'un fichier texte grâce à un script PHP. Mon fichier porte l'extension "txt" et les données sont séparées par des ";'. ...
0
by: Babs Mattel | last post by:
I'm new to database design and need some help. To make a simple music database, I've made a table of songs and a table of players joined by a bridge table (song_play) to allow many-to-many...
2
by: John | last post by:
I'm trying to normalize my database the best I can this time around and I'm running into some trouble. I've been avoid normalizing for a long time now because while I know how to normalize, I'm...
2
by: rjames.clarke | last post by:
I want to check if any of the items in a PHP array exist in a MySQL table. What is the best way to do this with making repeated calls to the database for each item? Actual application is: I...
0
by: tomzam | last post by:
I'm trying to get mysql working on Fedora Core 4. Actually trying to start the program mysqld without fatal errors. I posted this message first on the linux misc group - but no luck so far. Maybe...
3
by: TonyJH226 | last post by:
I’m using Access 2003 and am a novice to Access. I am creating a form to facilitate data entry to seven tables. The main table (A) has four sub-tables that are related to the main table by...
1
by: student001 | last post by:
How do you create a bridge table with 2 tables each containing the same information? For instance, tableA contains AID (key), aLastName, aFirstName...tableB contains CID (key), cLastName,...
2
by: viki1967 | last post by:
Hi everyone. My table mysql is: ID Dist Date Hour 15 LT 22/10/2009 08:56:05 14 RM 22/10/2009 08:55:20 13 RM 22/10/2009 08:55:19 12 RM 22/10/2009 08:51:22
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.