On 2015/01/09 01:12, MikeSnow wrote:
I was wondering if anyone could let me know where I am going wrong. I am
getting the error...
"Error while executing query: no such column: t1.*B.Switch-Tower-Sector"
but, the column,  t1.[*B.Switch-Tower-Sector], does exist.  I get results
when I do
select[*B.Switch-Tower-Sector] from t1;
but an error when I do the UPDATE statement...

UPDATE t2
SET     [*B.ANT_ORIENTATION] =
(SELECT t2.ANT_ORIENTATION
FROM t2
WHERE
t2.[*SSID-CELLID-SECTOR] = t1.[*B.Switch-Tower-Sector]);

Hi Mike,

There are many things that might be improved here, and one thing that is 
definitely wrong.

In the Update Query, you are asking the DB to set a column named "*B.ANT_ORIENTATION" in a Table called "t2" to another value in a column called "ANT_ORIENTATION" selected from the same table "t2" which can be found in some row it has to look up by seeing where the "*SSID-CELLID-SECTOR" column equals a value that can be found in a column called "*D.Sqitch-Tower-Sector" in a Table called "t1" - But where is this table "t1" referenced in the query? Nowhere - not in the UPDATE clause, not in the FROM clause, how must it know what t1 refers to?

Even if the table exists in the database, you cannot just reference some column from it without telling the query to scan that table in a FROM clause.

Even then, if you add that table to the from clause by means of a join or such, you still need to tell it explicitly which row to look up... The value for that column must be compared for which row?

Then, how must it distinguish between table t2 in the Update clause and t2 in 
the SELECT clause? You need a bit of an Alias I think.

I will try to re-write the query here to what I /THINK/ might be a pseudo-query 
of what you intended, but this is just a guess:

UPDATE t2 SET [*B.ANT_ORIENTATION] = (
  SELECT SS.ANT_ORIENTATION
    FROM t2 AS S2
    LEFT JOIN t1 AS S1 ON S2.[*SSID-CELLID-SECTOR] = S1.[*B.Switch-Tower-Sector]
  WHERE S2.[SOME_ID]=t2.[SOME_ID]  (...or perhaps 
S1.[SOME_COLUMN]=t2.[SOME_COLUMN]?)
);

If you give us the table layouts (schemata) and explain in simple terms what answer you need from the query, we'd be able to make a more accurate suggestion on best query to use.

PS: While The MS SQL SERVER type brackets [ and ] are allowed in SQLite because of niceness, it isn't best practice or correct SQL. The SQL standard calls for enclosing columns and table object names in double quotes: "column_name"; and values in single quotes: 'value'. Another less than optimal practice is using SQL-specific control characters in object names, such as the asterisk - or having columns or aliases that are reserved words for the specific engine. It should mostly work though.


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to