On 22-Aug-2001 Jeremy Morano wrote:
> Hi ,
>
> I was wondering if there was a way to retreive a column_name instead of a
> value in an sql select query?
>
> For example if my table has the field firstname, lastname, telephone,
> movie1, movie2, movie3......
>
>
> And my first record is John Doe 555-5555
> good bad bad
> My second record is Jane Doe
555-6666 good
> good bad
>
> I would like to know which movies Jane Doe rated "good"'...............Is
> this possible and if so how?
>
So when a new movie is released you alter the table ?
I suppose you probably could :
select movie1, ... where lastname='Doe' and firstname='Jane'
where 'good' in (movie1,movie2, ...)
Then have your application check the movie(x) values.
But it would be a mondo kludge around a poor table design.
Consider normalizing the data instead -
user table:
id
name
phone
movie table:
id
name
rating table:
usrid
movid
rate enum('excellent','good','fair','bad','excrement')
The query becomes
SELECT m.name
frommovie as m, rating as r, user as u
where movid=m.id and usrid=u.id
and u.name='Jane Doe' and rate='good';
Regards,
--
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.
(53kr33t w0rdz: sql table query)
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php