madness69 Posted December 8, 2012 Share Posted December 8, 2012 Could someone tell me what is the query for what im trying to do, for example: i have 2 tables, one is "comments" table and the other is "articles" tables. In the comments table there is a 3 columns (id, title, message) and in the articles table there is 3 columns too(id, title,info) I would like is to get all the data of the column message from the table "comments" but the table "comments" got to have the same title of the column title of the column title of Articles table. I dont no if im beign confusing, im sorry. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 8, 2012 Share Posted December 8, 2012 Not much point in storing a title in the comments table then. How do you know which comments belong to which article? Quote Link to comment Share on other sites More sharing options...
madness69 Posted December 8, 2012 Author Share Posted December 8, 2012 (edited) The title given is a unique name and are the same name in the coment and article Edited December 8, 2012 by madness69 Quote Link to comment Share on other sites More sharing options...
kicken Posted December 8, 2012 Share Posted December 8, 2012 You should be linking the comments with the article by the article's ID number, not the title. It's quicker to compare a couple of INTs than it is to compare strings. It would also use a lot less space on the system to store those INTs than to store a copy of the title. You also won't have any issues if the article title ever gets changed. Quote Link to comment Share on other sites More sharing options...
madness69 Posted December 9, 2012 Author Share Posted December 9, 2012 (edited) yes i know, and how would be the query for it? Here is the tables: table comments: - id; - name; - email; - message; -id_article; table articles: -id; - title; - contents; Edited December 9, 2012 by madness69 Quote Link to comment Share on other sites More sharing options...
kicken Posted December 9, 2012 Share Posted December 9, 2012 Just do a JOIN between the two tables using the title columns as the join's condition. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 9, 2012 Share Posted December 9, 2012 I would like is to get all the data of the column message from the table "comments" but the table "comments" got to have the same title of the column title of the column title of Articles table. According to to OP all that is required is message column from comments table. I am totally confused about requirements here. It's later been established that title columns are the same so why mention that constraint. Quote Link to comment 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.