keenlearner Posted February 25, 2007 Share Posted February 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/40049-better-query-than-this/ Share on other sites More sharing options...
effigy Posted February 25, 2007 Share Posted February 25, 2007 You could use GROUP_CONCAT, but I would only do this if it aids the receiving code. Repetition is less of a concern when you're pulling data out of a database, but moreso when you're putting data in. Quote Link to comment https://forums.phpfreaks.com/topic/40049-better-query-than-this/#findComment-193753 Share on other sites More sharing options...
fenway Posted February 26, 2007 Share Posted February 26, 2007 What you really need is another table. Quote Link to comment https://forums.phpfreaks.com/topic/40049-better-query-than-this/#findComment-194452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.