View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 07:33 AM
onedbguru@firstdbasource.com
 
Posts: n/a
Default Re: Easier way then to use a join here?

Not seeing any details about the table layout or what the end goal is,
I can only speculate and give you a method that I would choose.

It appears that this is a table that stores user preferences and then
does something on the display based on those preferences.

create table pref (uid integer, prefq integer, prefanswer integer) !!
I prefer to use integers where value will always be a number.
create table userinfo (uid integer, username varchar, fname varchar,
lastname varchar....)
questiontbl
answtbl

insert into pref values (1,30,7507)
insert into pref values (1,41,9108)
insert into pref values (1,45,10032)
insert into pref values (2,30,7506)
insert into pref values (2,41,9107)
insert into pref values (2,45,10031)

now I can select/join them all together in one query.

select a.uid, b.prefq, c.prefanswer
from pref a, questiontbl b,anstbl c
where a.uid=123 and b.prefq=a.prefq and c.prefanswer=a.prefanswer

Now, all you need is the uid (user id) and you can retrieve all of the
questions and all of the answers in one query. And this would be very
fast as these "primary keys" would/could be indexed making retrieval
very fast.

One thing you will need in any case like this would be a way to ensure
that answer xyz goes with question 123 etc...

As always, YMMV

Reply With Quote