Ashok
Ashok

Reputation: 5655

How to prepare column names dynamically in a sql query in sqlite?

A table in SQLite DB contains 52 columns and their name as follows size0,size1,size2,size3,....size49,category,priority.

while preparing the query for getting the values in only sizes columns i'm writing the query as

select size0,size1,size2,size3,....size49 from myTableName.

Can we prepare these column names dynamically in a loop( because all size columns are in logical order ) within the query it self?

and that query should work in sqlite.

Any comments or suggestions would be appreciated.

Thank you in advance.

Upvotes: 0

Views: 1510

Answers (2)

LS_ᴅᴇᴠ
LS_ᴅᴇᴠ

Reputation: 11161

In SQLite, you can't change columns number or column definition in a query with plain SQL.

Anyways, this MUST be a horrible database design. Consider normalizing your schema, as I can't believe 200 size columns is a correct solution to any real problem.

Upvotes: 2

Adrian Cornwell
Adrian Cornwell

Reputation: 196

you could do

SELECT * FROM mytablename

The * will return all data (columns) from the table.

Upvotes: 0

Related Questions