1

I am trying to run this query but doesn't run

SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id = '1'pd.id = ng.post_id
ORDER BY ng.order

and getting error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pd.id = ng.post_id ORDER BY ng.order' at line 1

i've tried `ng.order` and `ng`.`order` but still cant seem to get it to run.

Any help is much appreciated

1

3 Answers 3

2

I think you're just missing an and:

AND ng.parent_id = '1'pd.id = ng.post_id

should probably be:

AND ng.parent_id = '1'
AND pd.id = ng.post_id

Or better, put the join condition in the join (and don't quote your numbers unless they really are strings):

SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng join `ecom_page_data` AS pd on ng.post_id = pd.id
WHERE ng.cluster_key = 'primary'
AND ng.tab = 0        -- Leave the quotes on if tab is a string
AND ng.parent_id = 1  -- Leave the quotes on if parent_id is a string
ORDER BY ng.order
Sign up to request clarification or add additional context in comments.

2 Comments

as if I did not see that!! Cheers
@Phil: Come on, how many times has it been something that couldn't possibly be wrong? More than once no doubt :)
1

try

ng.order

if i could get backticks to show in this editor, then they would be there, but it seems to remove them

backticks are used to escape reserved words and spaces in column names etc

Comments

0

Change your query to (you have a ' misplaced)

SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id =  '1' AND pd.id = ng.post_id
ORDER BY ng.order

OR

SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id =  1 AND pd.id = ng.post_id
ORDER BY ng.order

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.