query with multi table
Posted: Sun Feb 25, 2007 9:20 am
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 :
link table:
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 aaaa| descriptionaaaaaaaa | url aaaaaaaaaaa |
2 | page one | This is the page one | http://www.link-1.com |
2 | page one | This is the page one | http://www.link-2.com |
2 | page one | This is the page one | http://www.link-3.com |
sorry, i can't draw table properly here.
So the problem is, i need the http://www.link-1.com, http://www.link-2.com and http://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.[/syntax]
html table :
Code: Select all
create table html(
id int(4),
title varchar(255),
description varchar(255)
);Code: Select all
create table link(
id int(4),
url varchar(255)
);"SELECT * FROM html LEFT JOIN link using(id) WHERE html.id = '2' "; it will output,
id | title aaaa| descriptionaaaaaaaa | url aaaaaaaaaaa |
2 | page one | This is the page one | http://www.link-1.com |
2 | page one | This is the page one | http://www.link-2.com |
2 | page one | This is the page one | http://www.link-3.com |
sorry, i can't draw table properly here.
So the problem is, i need the http://www.link-1.com, http://www.link-2.com and http://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.[/syntax]