Reputation: 10288
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
Upvotes: 1
Views: 201
Reputation: 63956
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
Upvotes: 0
Reputation: 434665
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
Upvotes: 2
Reputation: 10214
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
Upvotes: 1