Jump to content

Better query than this ?


keenlearner

Recommended Posts

Ok, let's go straight to the point with the simple example, let's say i have two tables namely html and link.

html table :

create table html(
id int(4),
title varchar(255),
description varchar(255)
);

 

link table:

create table link(
id int(4),
url varchar(255)
);

 

one page of website can have only one title and description, but can have many url which will be retrieved from link table, let's say I want the data to appear on page-one.php so i query with

"SELECT * FROM html LEFT JOIN link using(id) WHERE html.id = '2' "; it will output,

id  | title        | description              | url                                |

2  |  page one  | This is the page one  | www.link-1.com  |

2  |  page one  | This is the page one  | www.link-2.com  |

2  | page one  | This is the page one  | www.link-3.com  |

 

sorry, i can't draw table properly here.

 

So the problem is, i need the www.link-1.com, www.link-2.com and www.link-3.com, and i need the title and description only once but it was repeated for three times which i afraid it's not efficient to repeat the same thing so many times and i was thinking if there is a way to show the three url but only one time of title and description ? in other words is there a better query than this ? Thank you.

Link to comment
https://forums.phpfreaks.com/topic/40049-better-query-than-this/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.