RODBC sqlQuery: name with special character # - ms-access

I am using RODBC to merge two tables in ACCESS. Here are my codes:
qry <- "SELECT * FROM
table1 LEFT OUTER JOIN table2
ON table1.Ref# = table2.Ref# "
result <- sqlQuery(connection, qry)
str(result)
Which returns the following error message:
"42000 -3100 [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression
I believe it's because I didn't use "table1.Ref# = table2.Ref#" correctly. With the special character, how can I modify this query? Thank you very much in advance.

Try wrapping the field names with special characters inside square brackets.
SELECT
*
FROM
table1
LEFT JOIN
table2
ON
[table1].[Ref#] = [table2].[Ref#]
Also Access does not support OUTER Join, so simply try LEFT Join.

Related

redash SQL query inner join with query

I am using redash to display data and am struggling to figure out how to show only specific images for this join query.
The problem is with my last AND condition which seems to break the query (AND "images"."imageable_type" = "BrandProfile"). Below is the error message I am receiving.
Error running query: column "BrandProfile" does not exist LINE 31: ...s"."height" = 760 AND "images"."imageable_type" = "BrandProf... ^
SELECT "brand_profiles"."company_name",
"users"."full_name",
"brand_profiles"."location",
"brand_profiles"."company_website",
"brand_profiles"."description",
"images"."processed_url"
FROM "brand_profiles"
INNER JOIN "users" ON "users"."id" = "brand_profiles"."user_id"
INNER JOIN "images" ON "images"."imageable_id" = "brand_profiles"."id" AND "images"."height" = 760 AND "images"."imageable_type" = "BrandProfile"
WHERE "brand_profiles"."deleted_at" IS NULL
AND "brand_profiles"."marketplace" = true
Could you try to replace "BrandProfile" with 'BrandProfile'. Also would recommend to read the post When to use single quotes, double quotes, and backticks in MySQL that explains how behaviour of ANSI_QUOTES mode.

Getting error Error Code: 1064. You have an error in your SQL syntax

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.

SQL query access pivot - error message 'field that has an invalid data type'

I'm running an SQL Query on MS Access.
the query looks like this:
TRANSFORM MIN(X_VALUE*MULTIPLE & ' ' & Y_VALUE)
SELECT A.ID
FROM ((MY_TABLE_A A
INNER JOIN MY_TABLE_B B ON B.ID = A.ID)
INNER JOIN MY_TABLE_C C ON C.FOO1_ID = A.FOO1_ID)
LEFT JOIN MY_TABLE_D D ON A.FOO2_ID = D.FOO2_ID
WHERE A.NUM ='FOO'
AND A.FOO_ID<>0
AND FOO3=1
GROUP BY A.ID PIVOT X_NAME IN('BLAH1', 'BLAH2')
when running this against local MDB file, it works.
when running this against Linked MDB (tables are linked to remote Oracle DB), I'm getting
ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] The Microsoft
Access database engine could not execute the SQL statement because it
contains a field that has an invalid data type.
I've googled it, and couldn't find anything useful.
Any idea what can I do?
thanks.
The only statement in the query that even vaguely seems it would cause data type issues is the mixed types in the transform statement. Perhaps the following would work:
TRANSFORM MIN(CSTR(X_VALUE*MULTIPLE) & ' ' & CSTR(Y_VALUE))

Join on Join mysql

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.

MySQL Query 2 inner join?

I have a problem with my sql query in mysql. in sqlite3 and sql server all works.
SELECT `buildings`.*
FROM `buildings`
INNER JOIN "floors"
ON "floors"."building_id" = "buildings"."id"
INNER JOIN "spaces"
ON "spaces".floor_id = "floors".id
maybe i need to process on other way in mysql?
thanks
MySQL treat words in quotes ("floors") as strings, so those values are NOT used as table/field names. Try
SELECT ...
...
INNER JOIN floors ON floors.building_id = buildings.id
INNER JOIN spaces ON spaces.floor_id = floors.id
instead. Backticks around table/field names are required ONLY when the table/field name is a reserved word. buildings is not a reserved word, so no backticks are necessary.
ANSI_QUOTES may not be enabled. From the manual ref:
If the ANSI_QUOTES SQL mode is enabled, it is also permissible to quote identifiers within double quotation marks:
mysql> CREATE TABLE "test" (col INT);
ERROR 1064: You have an error in your SQL syntax...
mysql> SET sql_mode='ANSI_QUOTES';
mysql> CREATE TABLE "test" (col INT);
Query OK, 0 rows affected (0.00 sec)
Make sure ANSI_QUOTES is enabled, or just stick with the traditional backtick (`)
This is also, from your vague question, assuming I have the correct problem to chase.
SELECT `buildings`.*
FROM `buildings`
INNER JOIN `floors`
ON `floors`.`building_id` = `buildings`.`id`
INNER JOIN `spaces`
ON `spaces`.`floor_id` = `floors`.`id`
or
SELECT buildings.*
FROM buildings
INNER JOIN floors
ON floors.building_id = buildings.id
INNER JOIN spaces
ON spaces.floor_id = floors.id
Do not use : ".
This is for String in MySql.