For some reason I get the following error when running the code below:
#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 'FROM postcodes_demographics INNER JOIN latlon1 on postcodes_demographics.postc' at line 3
I don't understand what I'm doing wrong, thanks for any suggestions!
INSERT INTO pslatlong
SELECT postcodes_demographics.*, latlon1.*,
FROM postcodes_demographics
INNER JOIN latlon1
on postcodes_demographics.postcode = latlon1.postcodens;
You have an errant comma:
SELECT postcodes_demographics.*, latlon1.*, <--- HERE
Remove it.
I would be very surprised if merely removing the comma fixes the problem. When using insert, you should get in the habit of listing all the columns explicitly:
INSERT INTO pslatlong(col1, col2, . . . )
SELECT d.col1, l.col2, . . .
FROM postcodes_demographics d INNER JOIN
latlon1 ll
on d.postcode = ll.postcodens;
You need to do this to be sure that the right column is assigned the right value, to allow auto incrementing columns to be auto-incremented, and to prevent problems based on the number of columns.
This may works:
INSERT INTO pslatlong
SELECT postcodes_demographics.*, latlon1.*
FROM postcodes_demographics
INNER JOIN latlon1
on postcodes_demographics.postcode = latlon1.postcodens;
Related
I have two tables that I'm trying to connect. One table is called 2019projections and the other is called 2019actualstat. I want to connect the two by names. I'm 99% sure every name that is in 2019actualstat is in 2019projections, but not every name in 2019actualstat is in 2019projections. The latter has alot more names, but most of them are useless.
I've tried left join and right join.
I've tried select distinct
I gave a shot at exists
This is what I have so far:
USE Fantasyfootball;
SELECT DISTINCT *
FROM 2019actualstat;
LEFT JOIN 2019projections ON
2019actualstat.Player =
2019projections.first_last;
It's giving me the 1064 error, but I think it has to do with the 2019projections table having more records.
21:27:26 LEFT JOIN 2019projections ON 2019actualstat.Player =
2019projections.first_last 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 'LEFT JOIN 2019projections ON
2019actualstat.Player = 2019projections.first_last' at line 1 0.00071
sec
2019projections.first_last is a varchar(50) and 2019actualstat.player is text
PS: I have the .csv files which I'm not sure how to post, but I would be happy to send them both.
You're missing the select list, and have a redundant (wrong) semicolon at the end of the from clause:
SELECT *
FROM 2019actualstat
LEFT JOIN 2019projections ON 2019actualstat.Player = 2019projections.first_last;
The query that is throwing an error for my MySQL DB is:
SELECT t1.GROUPNAME FROM user_group t0, group t1 WHERE ((t0.users_USERNAME =
?) AND (t1.GROUPNAME = t0.groups_GROUPNAME))
The error info is the following:
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 'group t1 WHERE
((t0.users_USERNAME = 'test') AND (t1.GROUPNAME = t0.groups_GROUP')
Okay so I know the problem is with the group t1 part. But I dont know what is wrong with it.
Click here to see that I have all the needed colums
Can any one find out what the problem could be here?
group is a reserved word in SQL. You should put quotes around it.
Some JPA providers do that automatically, whereas others don't ...
This it the code I am trying to execute:
SELECT ID_K
FROM koncert,
programi
WHERE koncert.ID_K = programi.ID_K
GROUP BY koncert.ID_K
HAVING COUNT (DISTINCT programi.Salla) = 2
It returns this error:
#1064 - 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 'DISTINCT programi.Salla)=2 LIMIT 0, 25' at line 4.
Tried to change different things but it still won't work .
You should use the count(DISTINCT programi.Salla
) and not count (..) ..remove space between COUNT and (...
SELECT koncert.ID_K
FROM koncert
INNER JOIN programi on koncert.ID_K = programi.ID_K
GROUP BY koncert.ID_K
HAVING COUNT(DISTINCT programi.Salla) = 2
but you need also tablename for avoid ambiguity and use explicit join sintax too
First you should use qualified name for your column, when column name is same in both table
SELECT ID_K FROM
should be
SELECT programi.ID_K FROM
else, you will get ambiguous column error. Otherwise, your query looks fine except removing extra space when calling COUNT (#spencer already mentioned in comment)
Also, it is good practice to join your table using JOIN (or INNER JOIN, LEFT JOIN etc) keyword, which makes your query more clear and readable.
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.
I am getting an SQL ERROR (1064) Syntax. Is what i am trying to do allowed? As i don't see the syntax error.
`SELECT isc_products.prodname, isc_product_variations.* , isc_product_variation_combinations.vcoptionids,
FROM isc_products
JOIN isc_product_variations
ON isc_products.prodvariationid = isc_product_variations.variationid
JOIN isc_product_variation_combinations
ON isc_product_variation_combinations.vcvariationid = isc_product_variations.variationid`
You have isc_product_variations.variationid twice in your ON statements. Check, if this is what you want, or if there is a second key in you perhaps need isc_product_variations
You have an error on the first line. You have a comma that shouldn't be there:
SELECT isc_products.prodname,
isc_product_variations.* ,
isc_product_variation_combinations.vcoptionids,
-- ^
FROM ...
I'd also advise you not to use SELECT isc_product_variations.* but instead list the columns you want explicitly.