Jump to content

[SOLVED] CONCAT and JOIN


Ansel_Tk1

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.