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;
Related
I am new to MYSQL and I was trying to do an inner join but one of the columns is named TS%. It seems that the symbol at the end is causing this problem because when I remove this column it works just fine
SELECT Players.Player, Players.college, Seasons_Stats.Year, Seasons_Stats.Pos, Seasons_Stats.TS%
FROM Players
INNER JOIN Seasons_Stats on Players.Player = Seasons_Stats.Player;
Use backquote should resolve that strange column name :
SELECT Players.Player, Players.college, Seasons_Stats.Year, Seasons_Stats.Pos,
Seasons_Stats.`TS%` FROM Players INNER JOIN Seasons_Stats on Players.Player = Seasons_Stats.Player;
Because the % symbol in a MySQL syntax is used for some query operation.
Good Afternoon,
I am trying to update a table using price data from another table however I get an error using an inner join. I am sure its something very stupid but having spent the best part of my day on this its time to ask for help.
If I do the following SELECT statement to test my inner join syntax works as it should
SELECT *
FROM polaracc_osrs_property_field_value
INNER JOIN polaracc_osrs_properties
ON polaracc_osrs_property_field_value.pro_id = polaracc_osrs_properties.id
WHERE polaracc_osrs_property_field_value.field_id =112
However when I then try and run an update statement using the price from one table to populate the 2nd I get the below 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 'FROM polaracc_osrs_property_field_value INNER JOIN
polaracc_osrs_properties ' at line 3
The syntax used for the update statement is below
UPDATE polaracc_osrs_property_field_value
SET polaracc_osrs_property_field_value.value_integer = polaracc_osrs_properties.price
FROM polaracc_osrs_property_field_value
INNER JOIN polaracc_osrs_properties
ON polaracc_osrs_property_field_value.pro_id = polaracc_osrs_properties.id
WHERE polaracc_osrs_property_field_value.field_id = 112
Your join needs to happen before you set your values like this:
UPDATE polaracc_osrs_property_field_value
INNER JOIN polaracc_osrs_properties
ON polaracc_osrs_property_field_value.pro_id = polaracc_osrs_properties.id
SET polaracc_osrs_property_field_value.value_integer = polaracc_osrs_properties.price
WHERE polaracc_osrs_property_field_value.field_id = 112;
Hope this helps.
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.
Could someone please tell me what's wrong with this code that's making it spit back an error?
My code is as follows:
CREATE OR REPLACE VIEW vw_training AS
SELECT training.train_attended, clients.client_firstname, clients.client_lastname, clients.client_swn, clients.client_id, locations.loc_id, locations.loc_title, locationsp.loc_id, locationsp.loc_title,
FROM training
JOIN clients ON clients.client_id = training.train_clientid
JOIN locations AS locationsp ON locations.loc_id = training.train_pickup
LEFT JOIN locations ON locations.loc_id = clients.client_winz
And this is the error I'm getting back:
#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 training JOIN clients ON clients.client_id =
training.train_clientid JOIN' at line 3
I'm running phpmyadmin Version information: 3.5.2.2
I've used this script with different values before with no issues
You have an extra trailing comma before the FROM clause
SELECT ....,
locationsp.loc_id,
locationsp.loc_title, -- <<== remove this trailing comma
FROM training ...
and another error that will raise this message: Unknown column 'locations.loc_id' in 'on clause' is the use of tablename and not the alias supplied. it should be,
JOIN locations AS locationsp ON locationsp.loc_id = training.train_pickup
^^ should use alias here
I have (3) tables: Professor, Comment, Course
I'm trying to get a few columns to display the professor with all the courses and all the comments they have.
My tables
SQL:
SELECT prefix, code, info, date
FROM Course, Comment
JOIN Professor ON Professor.pID = Comment.pID
AND JOIN Course ON Course.cID = Comment.cID
WHERE Comment.pID = ?
Throws error:
Syntax error or access violation: 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 'JOIN Course ON Course.cID = Comment.cID WHERE Comment.pID = '273'' at line 4
SELECT prefix, code, info, date
FROM Comment
JOIN Professor ON Professor.pID = Comment.pID
JOIN Course ON Course.cID = Comment.cID
WHERE Comment.pID = ?
Just remove the AND before the second JOIN and remove Course in the From list. You may need to change the order of the tables depending on what table data you are primarily after.
Advise that you have a read through the MySQL JOIN syntax page.
change 'AND JOIN' to just 'JOIN'
There is no AND JOIN. Please read about JOIN syntax in the manual before attempting to use it.
Additionally, you reference table Course twice.