Mysql - What is the fastest way to retrieve records from multiple tables -


example: create table post -

post_id primary key  content varchar 

and create table comment -

comment_id primary key  post_id foreign key reference post(post_id)  content varchar 

show records in asp(active server pages)

query1: select * post;  while not rs1.eof { response.write rs1("post_id") response.write rs1("content")  query2: select * comment post_id = rs1("post_id")  while not rs2.eof {     response.write rs2("comment_id")     response.write rs2("content") } } 

the second query perform fullscan in table comment each record in table post, there way make comment search faster above method? need use index case? in advance

join tables,

select  a.*, b.*    post         inner join comment b             on a.post_id = b.post_id --   a.post_id = @valuehere       -- <<== if want specific post 

to further gain more knowledge joins, kindly visit link below:


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -