Ansel_Tk1 Posted December 24, 2008 Share Posted December 24, 2008 Hi - wondering if someone out there can help? Can CONCAT be used before JOIN to define the the two fields to be combined? Here is what I have so far: SELECT CONCAT(boomcms_mstlst_sections.section_id, ' ', boomcms_content_articles.smm_ct_title) AS smm_ct_titlewd FROM boomcms_content_articles, boomcms_mstlst_sections LEFT JOIN boomcms_mstlst_sections ON boomcms_mstlst_sections.section_id=boomcms_content_articles.section_name) and I get the error Not unique table/alias: 'boomcms_mstlst_sections' Any help would be really appreciated. Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/ Share on other sites More sharing options...
rhodesa Posted December 24, 2008 Share Posted December 24, 2008 you are using the short hand AND the long hand version of a JOIN. basically, you are trying to join boomcms_mstlst_sections twice. try this: SELECT CONCAT(boomcms_mstlst_sections.section_id, ' ', boomcms_content_articles.smm_ct_title) AS smm_ct_titlewd FROM boomcms_content_articles LEFT JOIN boomcms_mstlst_sections ON boomcms_mstlst_sections.section_id=boomcms_content_articles.section_name) also...aliases make your code much easier to read: SELECT CONCAT(s.section_id, ' ',a.smm_ct_title) AS smm_ct_titlewd FROM boomcms_content_articles a LEFT JOIN boomcms_mstlst_sections s ON a.section_name = s.section_id) Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/#findComment-723159 Share on other sites More sharing options...
Ansel_Tk1 Posted December 24, 2008 Author Share Posted December 24, 2008 Thank you so much rhodesa. And I love the McGuyver photo. Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/#findComment-723160 Share on other sites More sharing options...
rhodesa Posted December 24, 2008 Share Posted December 24, 2008 Thank you so much rhodesa. And I love the McGuyver photo. gracias Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/#findComment-723165 Share on other sites More sharing options...
Ansel_Tk1 Posted December 24, 2008 Author Share Posted December 24, 2008 Just one question - is CONCAT exclusive of all other fields in the table when it is used? i.e. does: SELECT CONCAT(boomcms_mstlst_sections.section_name, ' ', boomcms_content_articles.smm_ct_title) AS smm_ct_titlewd only select boomcms_mstlst_sections.section_name and boomcms_content_articles.smm_ct_title within those two tables and ignores all other fields in both tables within the query? I ask because I need to also obtain the field boomcms_content_articles.smm_ct_article_id however I think (maybe I am wrong?) since it is not within the CONCAT it is not selected? I don't want boomcms_content_articles.smm_ct_article_id to be added to the CONCAT though. Can CONCAT be combined with SELECT * somehow? I've been searching on the mySQL commands documentation but am having trouble locating a reference of combining the two. Thank you so much for any help. Dan Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/#findComment-723340 Share on other sites More sharing options...
rhodesa Posted December 24, 2008 Share Posted December 24, 2008 yeah, you can add it to the list of things selected: SELECT CONCAT(boomcms_mstlst_sections.section_name, ' ', boomcms_content_articles.smm_ct_title) AS smm_ct_titlewd, boomcms_content_articles.smm_ct_article_id or you can do a *: SELECT CONCAT(boomcms_mstlst_sections.section_name, ' ', boomcms_content_articles.smm_ct_title) AS smm_ct_titlewd, * Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/#findComment-723342 Share on other sites More sharing options...
fenway Posted December 26, 2008 Share Posted December 26, 2008 Actually, you have to use "*" first. And I prefer CONCAT_WS(). Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/#findComment-724137 Share on other sites More sharing options...
Ansel_Tk1 Posted December 29, 2008 Author Share Posted December 29, 2008 Thank you both for your help. Link to comment https://forums.phpfreaks.com/topic/138307-solved-concat-and-join/#findComment-725333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.