Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.