Recently when I tried to make changes to a menu I have in a word press website I received an error message saying
[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 'WHERE woocommerce_term_id = 110 AND meta_key = 'thumbnail_id'' at line 1]
SELECT * FROM WHERE woocommerce_term_id = 110 AND meta_key = 'thumbnail_id'
This is the query used
SELECT * FROM WHERE woocommerce_term_id = 110 AND meta_key = 'thumbnail_id'
For now I can still make changes to the site without any problems, but I still think that there'll be a problem when I go live with the site.
Does anyone know a fix for this?
You don't supply a table name in your select query:
SELECT * FROM WHERE woocommerce_term_id = 110 AND meta_key = 'thumbnail_id'
Should be something like:
SELECT * FROM <yourTableName> WHERE woocommerce_term_id = 110 AND meta_key = 'thumbnail_id'
SQL follows the protocol of:
--** pseudocode **
SELECT <tableColumns>
FROM <table or view>
WHERE <your conditions>
For now I can still make changes to the site without any problems, but
I still think that there'll be a problem when I go live with the site.
Most definitely, your query will fail straight away.
Table name is missing next to FROM, pls correctly provide the table name
SELECT * FROM <TABLENAME> WHERE woocommerce_term_id = 110 AND meta_key = 'thumbnail_id';
Please refer for basic mysql commands:
cse.unl.edu/~sscott/ShowFiles/SQL/CheatSheet/SQLCheatSheet.html
Related
I need to hint an index to MySQL in a left join through Ecto and it's being pretty difficult.
The closest I've got is this:
query = from(s in Dossier.School,
left_join: sc in fragment("subscription_coordinators use index (subscription_coordinators_school_products_idx)"),
on: fragment("school_id = ?", 1)
and fragment("product in ('reading', 'maths')")
and is_nil(sc.deleted_at),
select: s,
where: s.id == 1
)
# Ecto.Adapters.SQL.to_sql(:all, Dossier.Repo, query)
query |> Dossier.Repo.all
in IEx that compiles and generates SQL fine:
SELECT s0.`id`, s0.`name`, s0.`school_code`, s0.`deleted_at`, s0.`district_id`
FROM `schools` AS s0
LEFT OUTER JOIN (subscription_coordinators use index (subscription_coordinators_school_products_idx)) AS f1 ON (school_id = 1 AND product in ('reading', 'maths')) AND f1.`deleted_at` IS NULL WHERE (s0.`id` = 1)
but obviously the position of the table alias is wrong so actually running the query produces:
** (Mariaex.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 'f1 ON (school_id = 1 AND product in ('reading', 'maths')) AND f1.`deleted_at` IS' at line 1
(ecto) lib/ecto/adapters/sql.ex:436: Ecto.Adapters.SQL.execute_and_cache/7
(ecto) lib/ecto/repo/queryable.ex:130: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:35: Ecto.Repo.Queryable.all/4
The full query is much bigger with nearly a dozen left joins (though this is the only one that needs a hint) and all in Ecto. I want to keep the fragment as small as possible if it can be done.
This is only a temporary solution though. We'll ANALYZE TABLES soon so it's unnecessary.
It is not supported currently. Please open up an issue in the Ecto repository and we will discuss it. Thank you!
I was working on my new joomla website changed some appearing sittings then the syntax error came out in the main page and changed all the website design I tried to undo all the changes I made and the error still there
the message I got
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 ') AND c.access_view IN (0,1,1,5) AND c.restriction_18=0 ORDER BY
i.date_start D' at line 2
SELECT i.*,c.id as c_id, c.name as c_name,c.alias as c_alias,c.icon_url as c_icon_url,
r.name as r_name, img.path as img_path, img.name as img_name, img.ext as img_ext,
img.caption as img_caption
FROM l0ucm_djcf_categories c, l0ucm_djcf_items i
LEFT JOIN l0ucm_djcf_regions r ON r.id=i.region_id
LEFT JOIN ( SELECT img.id, img.item_id, img.name, img.path, img.ext, img.ordering, img.caption
FROM (SELECT * FROM l0ucm_djcf_images WHERE type='item' ORDER BY ordering) img GROUP BY img.item_id ) AS img
ON img.item_id=i.id
WHERE i.date_exp > '2015-07-25 16:44:45' AND i.published = 1 AND c.published = 1
AND i.cat_id=c.id AND i.cat_id IN (9,10,11,12,13,15)
AND i.type_id IN () AND c.access_view IN (0,1,1,5) AND c.restriction_18=0
ORDER BY i.date_start DESC limit 9
anyone can help me to find out from where I can solve this problem?
thank you all,
The problem is in the statement AND i.type_id IN ().
IN() function cannot get an empty value. You should check the php code that creates the query and add a validation to the variable to add the statement only if it not empty.
I'm learning sql from these wikibooks pages and I'm trying to answer the last question "Remove all boxes from saturated warehouses" using mysql syntax. The following is what I came up with on my own mainly using previous answers from the same page.
delete from Boxes as b
where b.Warehouse in (
select w.Code
from ( select *
from Warehouses) as w
where w.Capacity < ( select count(*)
from Boxes bb inner join Warehouses ww
on bb.Warehouse = ww.Code
group by bb.Contents) ) ;
The query for this question on the site is generating
this solution doesn't work with mysql 5.0.67
ERROR 1093 (HY000): You can't specify target table 'Boxes' for update in FROM clause
That's why I'm using multiple sub queries as a way to come around this mysql message. However, I have an error in my query and therefore it's not running.
Error Code: 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 'as b where b.Warehouse in ( select w.Code
from ( sel' at line 1
Any idea?
I assume Boxes and Warehouse are tables, you gave Boxes an alias and used it on the Warehouse table, that's probably why it didn't work. Maybe you should try with a query after 'delete from'.
I think your warehouses table returns from than one columns (since * is used). Replace * with the column u want to get the output from.
EDIT: I am using phpMyAdmin interface, and I have been copy/paste the codes from phpMyAdmin to here. The phpMyAdmin seems to run a "different code" as I run the following code, and generating some error message that are referring to that "different code", causing huge confusion.
** Final edit: It seems Safari is causing this: it run the "different query" when I try to run 2nd query below. Use Firefox instead, and it generate correct results. Thanks for the help and sorry for the confusion. **
I have two tables: newsFeeds, comments, where
** newsFeeds contains column PID, comments contains column FID.**
I want to join rows in two tables with matching PID = FID. My code is:
SELECT * FROM newsFeeds
INNER JOIN
(
SELECT * FROM
comments
)
ON comments.FID = newsFeeds.PID
and the error message is "#1248 - Every derived table must have its own alias".
I then add in AS newtb after ) according to other posts here. And the code is then:
SELECT * FROM newsFeeds
INNER JOIN
(
SELECT * FROM
comments
) AS newtb
ON newtb.FID = newsFeeds.PID
But another error shows up: #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 'INNER JOIN( SELECTFID,COUNT(*) AScount FROMcomments
LIMIT 0, 25' at line 8
I wonder how to correctly do this?
You should correct this by removing the derived table:
SELECT *
FROM tb_1 INNER JOIN
tb_2
ON tb_2.FID = tb_1.PID;
MySQL has a tendency to materialize derived tables, which hurts performance.
The answer to your question, though, is to add a name after the parentheses:
SELECT *
FROM tb_1 INNER JOIN
(SELECT *
FROM tb_2
) t2
ON t2.FID = tb_1.PID;
I'm trying to run a MySQL query via WordPress, to bring back a list of posts that I want to delete because they have no "like" votes (using someone else's plugin data). The query works perfectly in phpMyAdmin but gives a syntax error when I run it through WP... and I see absolutely no reason why it would do this.
Here's the query code, which checks for posts over 30 days old that have no corresponding "like" entry in wti_like_post (whether positive or negative):
$novotesquery = "SELECT * FROM $wpdb->posts
WHERE $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_date < DATE_SUB(NOW(), INTERVAL 30 DAY)
AND $wpdb->posts.ID NOT IN
(SELECT DISTINCT post_id FROM $wpdb->wti_like_post)" ;
$result = $wpdb->get_results($novotesquery);
The syntax error says there's a problem on the last line of the SQL (the SELECT in parentheses): "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 ')' at line 6".
When I run the query in phpMyAdmin (replacing "$wpdb->" with the table prefix), it works a treat. If anyone can tell me why the SQL query will run on the server and not in WP, I'd appreciate it.
Thanks in advance.
Perhaps it's just a matter of defensive parenthesis
$novotesquery = "SELECT * FROM {$wpdb->posts}
WHERE {$wpdb->posts}.post_type = 'post'
AND {$wpdb->posts}.post_status = 'publish'
AND {$wpdb->posts}.post_date < DATE_SUB(NOW(), INTERVAL 30 DAY)
AND {$wpdb->posts}.ID NOT IN
(SELECT DISTINCT post_id FROM {$wpdb->wti_like_post})" ;
Perhaps you should use $wpdb->query method instead of get_results and finally, perhaps wti_like_posts is not yet declared when your code runs.
What about die($novotesquery) right before "$result" line?