Why am I getting an "ambiguous column name" error in SQLite? - sql

I can't quite figure out why I'm getting the error. The call worked fine until I added the second where clause.
ambiguous column name: nanoProd.name:
SELECT
nanoProd.name AS prodName,
nanoProd.intro AS prodIntro,
nanoProd.prodText AS nanoText,
nanoFiles.fileLoc AS nanoFile
FROM nanoProd
LEFT JOIN nanoRelFiles on nanoFiles.rid = nanoRelFiles.file_id
LEFT JOIN nanoProd on nanoProd.rid = nanoRelFiles.item_id
WHERE nanoRelFiles.scr_type = 'prod' AND nanoRelFiles.fileUse = 'list'

Related

SQL INNER JOIN syntax Error BigQuery // New to SQL

I'm getting this error "No matching signature for operator = for argument types: INT64, STRING. Supported signature: ANY = ANY at [9:6]
" while trying to JOIN two table in BQ, Login ID column is listed in the two tables but BQ shows that there's an error on line 9enter image description here
SELECT
performance.name,
performance.ahtdn,
tnps.tnps,
FROM
`data-exploration-2023.jan_scorecard_2023.performance-jan-2023` AS performance
LEFT JOIN
`data-exploration-2023.jan_scorecard_2023.tnps-jan-2023` AS tnps
ON performance.login_id = tnps.login_id
I've checked the syntax for INNER JOIN online and on BQ documentation but I couldn't find the reason why I get this error.
The error should be due to trying to join INT64 and STRING column. It should be resolved casting the numeric column to text one like this:
CAST(performance.login_id AS STRING) = tnps.login_id
or cast the second one if it is the numeric.

SQL redshift: Updating a column with data from another table but get an error, why?

I am using redshift and have followed this from an example. But I get the error:
[42601] ERROR: syntax error at or near "INNER" Position:
UPDATE podcast_platform_episode_level
INNER JOIN podcast_country_codes
ON podcast_platform_episode_level.country = podcast_country_codes.country
SET podcast_platform_episode_level.country_label = podcast_country_codes.country_label
Try this
UPDATE podcast_platform_episode_level
SET country_label = podcast_country_codes.country_label
FROM podcast_country_codes
WHERE podcast_platform_episode_level.country = podcast_country_codes.country
I renamed a column to country_code in podcast_platform_episode_level to help avoid confusion. But still surpised this code below works when the code above does not
-- adds country_label data
UPDATE podcast_platform_episode_level
SET country_label = c.country_label
FROM podcast_country_codes c
WHERE c.country = country_code;

How can Inner join with where clause select's table with hexadecimal value?

Below code works fine:
$stmt = $DB_con->prepare("select tbl_items.*,tbl_basket.* from tbl_items INNER JOIN tbl_basket on tbl_basket.id_items = tbl_items.id
where tbl_basket.cookie_user = 100);
I get en error when I change it to this:
$stmt = $DB_con->prepare("select tbl_items.*,tbl_basket.* from tbl_items
INNER JOIN tbl_basket on tbl_basket.id_items = tbl_items.id
where tbl_basket.cookie_user = c2b32bbfd582389b7df8e89e5796aa27);
.
Error: Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not
found: 1054 Unknown column 'c2b32bbfd582389b7df8e89e5796aa28' in 'where clause' in
I think the problem is with inner join, However it works perfectly without inner join.
any solution?
Your working query suggests, that cookie_user is of a numeric type. If so, prepend 0x to the hexadecimal representation. That should work.
...
tbl_basket.cookie_user = 0xc2b32bbfd582389b7df8e89e5796aa27
...

#1054 - Unknown column 'Klanten.Klantnummer' in 'on clause'

I know that I have seen a couple of other questions about this error but I'm new to the sql JOIN so plz could you guy explain what I'm doing wrong.
Here's my query
SELECT Klanten.Klantnummer,`Barcode`, `Naam`, `BetaalStatus`, `ScanStatus`, `TijdScan`, `Prijs`
FROM `Klanten`, `kaart`
LEFT JOIN (`Intro`)
ON (Intro.KlantNummer = Klanten.Klantnummer)
WHERE kaart.KlantNummer = Klanten.Klantnummer
This is the Error I get like you have seen in the title
1054 - Unknown column 'Klanten.Klantnummer' in 'on clause'
And the db names are correct
Simple rule: Never use commas in the FROM clause. Always use proper, explicit JOIN syntax. If you did that, you would not have an error:
SELECT Klanten.Klantnummer,`Barcode`, `Naam`, `BetaalStatus`, `ScanStatus`, `TijdScan`, `Prijs`
FROM `Klanten` JOIN
`kaart`
ON kaart.KlantNummer = Klanten.Klantnummer LEFT JOIN
`Intro`
ON Intro.KlantNummer = Klanten.Klantnummer ;
The problem is that the precedence of , and JOIN are different. Hence, the table before the comma is not known to the ON clause.

ORA-00904 on join

I am trying to create the following view:
CREATE OR REPLACE VIEW AlbumDistribution AS
SELECT Album.Album_ID,
Album.title,
HasTrack.tracked,
FinishedTrack.released_title,
SUBSTR(Album.Album_ID, -1) is_distributed_as
FROM Album A
JOIN HasTrack HT
ON HT.Album_ID = A.Album_ID
JOIN FinishedTrack FT
ON HasTrack.OriginatesFrom = FT.OriginatesFrom
AND HasTrack.tracked = FT.version;
but I get the ORA-00904 error:
ERROR at line 6:
ORA-00904: "HASTRACK"."TRACKED": invalid identifier
Which I find very confusing, as I reference HasTrack.tracked before and there's no error. If I change the order of the statements, putting HasTrack.OriginatesFrom = FT.OriginatesFrom last then I get the same error but for HasTrack.OriginatesFrom.
You define an alias for this and other tables. You need to use the alias throughout the query:
CREATE OR REPLACE VIEW AlbumDistribution AS
SELECT A.Album_ID, A.title, HT.tracked,
FT.released_title, SUBSTR(A.Album_ID, -1) is_distributed_as
FROM Album A JOIN
HasTrack HT
ON HT.Album_ID = A.Album_ID JOIN
FinishedTrack FT
ON HT.OriginatesFrom = FT.OriginatesFrom AND
HT.tracked = FT.version;