The below TERADATA query is giving "SELECT * MUST HAVE A FROM CLAUSE" Error.
Previously it was working fine. If anyone can help.
Select *
FROM
( SELECT 4000 *,
ROW_NUMBER() OVER(ORDER BY 1) rnum
from dbname.tablename
where (1=1)
) A
where rnum>2000 and rnum <=4000
Related
I've looked at the other postings but I haven't seen a resolution for this.
CREATE TABLE newtable AS (SELECT * FROM yourtable) with no data ;
Then
with cte as (
select top 10* from yourtable
)
insert into newtable
select * from cte
select * from newtable
I get an error saying it expects a select and not an insert.
How would I accomplish inserting the cte into a table?
I have the following query:
SELECT
USERS.*,
ROWNUM AS RANK ,
4101 AS TOTAL
FROM
( (
SELECT
*
FROM
USER_LIST
WHERE
USER_LIST.USR_ID = 1)
UNION(
SELECT
*
FROM
USER_LIST)
) USERS
Which works completely fine, I would like to sort the results via 'ORDER BY'.
I've tried placing the 'ORDER BY' before the last parenthesis (before the USERS) but I get an error, please advise how can I use 'ORDER BY' in this query.
Thanks.
You need define order by after alias.
SELECT USERS.*,
ROWNUM AS RANK,
4101 AS TOTAL
FROM ((SELECT * FROM USER_LIST WHERE USER_LIST.USR_ID = 1) UNION (SELECT * FROM USER_LIST)) USERS ORDER BY ...
In SQL this command works ok:
Query
SELECT TOP 20 * FROM
(
SELECT ROW_NUMBER() OVER (ORDER BY t0.ProductId) AS [ROW_NUMBER], *
FROM Product AS [t0]
) AS [t1]
WHERE [t1].[ROW_NUMBER] > 0 * 20;
Now I try the same with SQLite. I know that I must replace TOP with LIMIT, but don't know where to put it.
I always get something like
Error
SQLite error near "(": syntax error" or "SQLite error near "*": syntax error".
And I am not sure that the command [ROW_NUMBER] or ROW_NUMBER() works in SQlite.
Query
SELECT *,
(
SELECT COUNT(*)
FROM Product b
WHERE a.ProductId >= b.ProductId
) AS rnum
FROM Product a LIMIT 20;
Screen Shot
See the documentation:
SELECT *
FROM Product
LIMIT 20
OFFSET 0 -- optional
SQlite doesn't support TOP. That is sql-server syntax. You have to use limit 20 instead.
I have the following sqlite db:
BEGIN TRANSACTION;
CREATE TABLE `table1` (
`Field1` TEXT
);
INSERT INTO `table1` VALUES ('testing');
INSERT INTO `table1` VALUES ('123');
INSERT INTO `table1` VALUES ('87654');
COMMIT;
This select returns the correct result:
select * from table1 where Field1 like '%e%';
However this one returns nothing?
select * from table1 where Field1 like '%2%';
Even Stranger in DB Browser for SQLite:
select * from table1 where CAST(Field1 AS Text) LIKE '%2%'
Returns:
1 Rows returned from: select * from table1 where CAST(Field1 AS Text) LIKE '2%' (took %3ms)
Maybe a bug? Drops the first %
A bug in DB browser. I raised an issue and its now been fixed in the nightlies.
I have this razor statement
sql = "SELECT * FROM CarBike" +
"Order By id OFFSET #0 ROWS FETCH NEXT #1 ROWS ;";
var result = db.Query(sql, offset, pageSize);
i am getting error
Incorrect syntax near the keyword 'By'.
Invalid usage of the option NEXT in the FETCH statement.
System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'By'.
Invalid usage of the option NEXT in the FETCH statement.
Please help me to correct this error
You need a space between CarBike and Order by
sql = "SELECT * FROM CarBike" +
" Order By id OFFSET #0 ROWS FETCH NEXT #1 ROWS ;";
NB: OFFSET/FETCH is SQL 2012+ only.
To achieve similar results in previous versions
select * from
(
select *, ROW_NUMBER() over (order by id) rn
from CarBike
) v
where rn between #0+1 and #0+#1
order by id