Jump to content

Recommended Posts

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

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)

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

 

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, *

 

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.