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
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
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
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
Related
SELECT
i.*,
ii.file_location
FROM group_shop_item i, group_shop_itemimage ii, group_shop_brand b
WHERE
i.brand_id = b.id
AND
b.brand_status_id = 1
AND
i.is_deleted = 0
AND
i.is_displayed = 1
AND
i.id = ii.item_id
AND
ii.is_main = 1
AND
i.deal_participate = 1
AND
i.brand_label_id IS NOT NULL
ORDER BY i.datetime_modified DESC;
This SQL query keeps throwing me a 1064. It seems to be on the last line which I've tried with and without the i table variable. I can't for the life of me catch the error, anyone can lend me another pair of eyes?
I'm throwing this as a RAW query into the in built Django function and building this query with string concatenation. This copy paste is directly from a print I've done from the command line. It's outputting neatly but isn't reading when I run the view on my browser.
Over 25 years ago ANSI Standard join syntax was adopted. You need to cease using comas between table names in the from clause.
SELECT
i.*
, ii.file_location
FROM group_shop_item i
INNER JOIN group_shop_itemimage ii ON i.id = ii.item_id
INNER JOIN group_shop_brand b ON i.brand_id = b.id
WHERE i.is_deleted = 0
AND i.is_displayed = 1
AND ii.is_main = 1
AND i.deal_participate = 1
AND i.brand_label_id IS NOT NULL
AND b.brand_status_id = 1
;
Regarding the 1064 error, please read this without the exact error message and the exact/full query we can't offer much insight into that.
The other thing you need to be careful of is that "select *" isn't good practice either.
Please help to fix this error:
SELECT SQL_CACHE p.user_id, p.project_id, p.cid, p.project_title, p.additional_info, p.buynow_price, p.date_added, p.highlite, p.project_details, p.views, p.bids, p.currentprice, p.currencyid, p.buynow, p.filtered_auctiontype, p.buynow_purchases, p.date_starts, p.buynow_qty_lot, p.items_in_lot, UNIX_TIMESTAMP(p.date_end) - UNIX_TIMESTAMP('2017-08-05 18:14:50') AS mytime, UNIX_TIMESTAMP(p.date_starts) - UNIX_TIMESTAMP('2017-08-05 18:14:50') AS starttime, p.donation, p.filter_budget, p.reserve, p.project_state, p.bid_details, p.filter_escrow, p.filter_gateway, p.charityid, p.jobs_price
FROM xxx_projects AS p
LEFT JOIN xxx_users u ON(p.user_id = u.user_id)
WHERE p.visible = '1'
AND p.status = 'open'
AND p.project_state = 'product'
AND u.status = 'active'
AND p.project_id IN (88414723, 5043541, 98506492, 36121136, 84626697, , 4408122, 49183201, 56318356, 89533629, 16433073, 70069844, 6242686, 8745727, 10816822, 8745727, 27902749, 41807041, 61556755, 46837725, 38855144, 69491982, 27240408, 20425411)
MySQL Error : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right
syntax to use near ' 4408122, 49183201, 56318356, 89533629, 16433073,
70069844, 6242686, 8745727, 10' at line 8
I think in db is empty record but i can'f find it...
You have a double comma in 84626697, , 4408122. Just remove one comma (i.e., make it 84626697, 4408122) and you should be good to go.
Not done any programming for a few years so am somewhat rusty again.
I have two tables users table and users_profiles table. I want to update users_profiles table on the condition that user_uid matches on both tables (users.user_uid and users_profiles.user_uid) and where users.user_login = 'johndoe' and users.user_uid = '11'.
It will be executed in a php script, so johndoe would actually be users username (whatever is stored in session and same for users_uid. For simplicitity i added dummy data.
I run the query in phpmyadmin and get syntax error near INNER JOIN. I just cannot figure out what i'm doing wrong (probably wrote it entirely wrong) and have spent few hours trying to work it out without success.
Heres my sql query.
UPDATE
users_profiles
SET
users_profiles.user_fname = 'John',
users_profiles.user_lname = 'Doe',
users_profiles.user_gender = 'male'
INNER JOIN
users
ON
users.user_uid = users_profiles.user_uid
WHERE
users.user_login = 'johndoe'
AND
users.user_uid = '11'
error i get when running sql query via phpmyadmin.
#1064 - 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 'ON users.user_uid, .user_uid FROM users_profiles WHERE
users.user_login ' at line 7
Thanks.
Try this:
UPDATE
users_profiles
INNER JOIN
users
ON
users.user_uid = users_profiles.user_uid
SET
users_profiles.user_fname = 'John',
users_profiles.user_lname = 'Doe',
users_profiles.user_gender = 'male'
WHERE
users.user_login = 'johndoe'
AND
users.user_uid = '11'
Try to exchange SET and INNER JOIN as shown, for example, in this SO answer:
UPDATE
users_profiles p
INNER JOIN
users u
ON
u.user_uid = p.user_uid
SET
p.user_fname = 'John',
p.user_lname = 'Doe',
p.user_gender = 'male'
WHERE
u.user_login = 'johndoe'
AND
u.user_uid = 11
I dont understand this error, guys please help me. why I am getting this error..
Is there something wrong in my query?
this is the error..
#1064 - 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 'LIMIT 0, 25' at line 7
and this is my query:
SELECT
equivalent
FROM
tb_student_record
INNER JOIN
tb_student ON tb_student_record.stud_id = tb_student.stud_id
WHERE
tb_student_record.instructor_id = 'INST-20131296'
AND tb_student_record.criteria_id = '1'
AND tb_student_record.class_record_id = '1'
AND (CONCAT(stud_fname, ' ', stud_lname) = 'Jeffrey Oliveras'
AND tb_student_record.term = 'Prelim'
you are missing closing paranthesis at concat function
SELECT equivalent FROM tb_student_record INNER JOIN tb_student ON tb_student_record.stud_id=tb_student.stud_id
WHERE tb_student_record.instructor_id = 'INST-20131296'
AND tb_student_record.criteria_id = '1'
AND tb_student_record.class_record_id = '1'
AND (CONCAT(stud_fname, ' ', stud_lname) = 'Jeffrey Oliveras' )
AND tb_student_record.term = 'Prelim'
It seems that your query have problem at the end:
I need to update a table and this is my sql code so far but i'm getting the following error message:
Line 30: Incorrect syntax near ')'.
UPDATE dbo.Part
SET SupplierShortName = NationalSupplier.ShortName,
SupplierLongName = NationalSupplier.LongName
SELECT *
FROM dbo.Part
JOIN dbo.NationalSupplier
ON Part.SupplierNumber = NationalSupplier.Number
AND (ISNULL(Part.SupplierShortName,'') <> ISNULL(NationalSupplier.ShortName,'')
OR ISNULL(Part.SupplierLongName,'') <> ISNULL(NationalSupplier.LongName,''))
LEFT OUTER JOIN dbo.NationalPart
ON Part.NationalPartID = NationalPart.NationalPartID
WHERE Part.DWCreationEntityID = 1
AND NationalPart.NationalPartID is NULL
Thanks in advance for any valuable tips !
Try this:
UPDATE dbo.Part
SET SupplierShortName = NationalSupplier.ShortName,
SupplierLongName = NationalSupplier.LongName
FROM dbo.Part
JOIN dbo.NationalSupplier
ON Part.SupplierNumber = NationalSupplier.Number
AND (ISNULL(Part.SupplierShortName,'') <> ISNULL(NationalSupplier.ShortName,'')
OR ISNULL(Part.SupplierLongName,'') <> ISNULL(NationalSupplier.LongName,''))
LEFT OUTER JOIN dbo.NationalPart
ON Part.NationalPartID = NationalPart.NationalPartID
WHERE Part.DWCreationEntityID = 1
AND NationalPart.NationalPartID is NULL
You should alias the table names to make things concise.