Forum Moderators: open

Message Too Old, No Replies

MySQL select question of the dumb newbie variety

         

jdbnd

11:05 pm on Oct 25, 2008 (gmt 0)

10+ Year Member



So here's my issue: I have a database table that contains information on degree programs offered by a set of schools (think "BA in History from UCLA"). One row per degree program, and of course multiple degree programs per school. I also have a field that stores a unique ID for the school, though the table key is obviously associated with the specific school+degree combo. I should no doubt be using multiple tables, but my web host has pmadb turned off so I'm not sure how to set that up.

Let's say for example that I have a couple of fields called "degree_business," "degree_history" etc. They have binary values and tell me whether the row/degree in question is a business degree or a history degree (1=yes). So - what I am trying to do is a query that looks at all rows associated with, say, school #42, and if the "degree_business" field has a value of 1 in any one of those rows, returns a value of 1 for the question "does school #42 offer any business degrees".

Could anybody point me in the right direction / let me know the proper query type/syntax? I feel like it's probably a very remedial question, but any help would be greatly appreciated.

Thanks,
Joe

phranque

12:46 am on Oct 27, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



something like this might work:
SELECT MAX(degree_business) AS degree_offered FROM school_degrees_table WHERE school_id='42' GROUP BY school_id

as you mentioned, you probably have some db normalization issues.

jdbnd

12:44 am on Oct 29, 2008 (gmt 0)

10+ Year Member



Thanks, I appreciate it - will give it a shot.

Joe