SQLite: No Column Names In Output of Select Statement - sql

I am new to SQLite and trying to work my way through the basics. The problem is when I give it a simple command:
select * from newTable;
The output is as follows:
GoodState|GoodCapital
ShittyState|Raleigh
Which does not provide the column names on the output. My column names are: State and State_Capital
Is there any option available to make the column names show up on the top of the columns outputted like in MySql?

Oh. My bad. I should've googled more thoroughly.
The answer is:
.headers on
This enabled column headers in output.

Related

SQLPlus doesn't find values with where clause

I've imported a CSV file to an Oracle DB table. If I'm querying the first ten rows with a few columns it's no problem as you can see.
But if I want to the value "EDEKA-Neukauf" in column "Firma" with the where clause it returns that there's no row selected. As you can see here:
Does somebody has a solution? Because it seems like the columns were imported correct
The answer is that the where clause has to be combined with like, this will look like: where Firma like '%EDEKA-Neukauf%' . Thanks to Albin Paul.

Add Column to SAS via Proc SQL Statement

I haven't been able to find this exact question - but it seems simple enough that it's likely been asked before. I apologize in advance if my search skills aren't up to par...
Anyhow, I am trying to create a 'source_flag' column, appended to several tables I'm creating. Basically, each year and payment type has it's own table. I can query and manipulate each table individually, but I'm joining them all together (full join) at the end of the process. I want to create a column with each observation equal to the table the data came from.
For example, I want to join six tables:
2019_PD
2020_PD
2019_PB
2020_PB
2019_PN
2020_PN
All I want to do, is in the query for each table, create a column assigning the table name to the entire row, so that I know where each row came from.
proc sql;
create table 2020_PD as select
...,
...,
...,
"2020_PD" as source_flg,
.
.
.
;
quit;
Right now SAS is trying to find a field called 2020_PD - which obviously doesn't exist. Is there an easy way to do this within the proc statement? I'm not trying to add additional data steps since I'm doing this with too many tables to make that viable.
Thank you!!
SQL uses single quotes to delimit strings. So use:
'2020_PD' as source_flg,
The double quotes are interpreted as escape characters for an identifier, which is why you are getting an unknown column error.

BigQuery - How to query the number of columns in a table?

I want to query a table to get how many columns in that table and the name of each column. this post tells us how to do it in BQ command line interface, but can we do it using query?
From the following doc, it seems that the meta-tables won't give this kind of information. So, I guess the answer is no.
https://cloud.google.com/bigquery/querying-data#using_meta-tables
You can try this
SELECT
count(*)
FROM
`project`.dataset.INFORMATION_SCHEMA.COLUMN_FIELD_PATHS
where
table_name="table_name"

LIKE operator in SQL Server

I want to get all the records from the one table which contain at least one word from the input string. For example, input parameter='Stack over flow':
select *
from sample
where name like '%stack%'
or name like '%over%'
or name like '%flow%'
How do I search for records which contains 'stack' or 'over' or 'flow'?
The code you gave should work. But don't use it. It won't be able to use any indexes, and so will likely be very slow. Look into a full text index and the CONTAINS keyword instead.

Oracle DB simple SELECT where column order matters

I am doing a simple SELECT statement in an Oracle DB and need to select the columns in a somewhat-specific order. Example:
Table A has 100 attributes, one of which is "chapter" that occurs somewhere in the order of columns in the table. I need to select the data with "chapter" first and the remaining columns after in no particular order. Essentially, my statement needs to read something like:
SELECT a.chapter, a. *the remaining columns* FROM A
Furthermore, I cannot simply type:
SELECT a.chapter, a.*
because this will select "chapter" twice.
I know the SQL statement seems simple, but if I know how to solve this problem, I can extrapolate this thought into more complicated areas. Also, let's assume that I can't just scroll over to find the "chapter" column and drag it to the beginning.
Thanks.
You should not select * in a program. As your schema evolves it will bring in things you do not know yet. Think about what happens when someone add a column with the whole book in it? The query you thought would be very cheap suddenly starts to bring in megabytes of data.
That means you have to specify every column you need.
Your best bet is just to select each column explicitly.
A quickie way to get around this would be SELECT a.chapter AS chapterCol, a.* FROM table a; This means there will be one column name chapterCol (assuming there's not a column already there named chapterCol. ;))
If your going to embed the 'SELECT *' into program code, then I would strongly recommend against doing that. As noted by the previous authors, your setting up the code to break if a column is ever added to (or removed from) the table. The simple advice is don't do it.
If your using this in development tools (viewing the data, and the like). Then, I'd recommend creating a view with the specific column order you need. Capture the output from 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS' and create a select statement for the view with the column order you need.
This is how I would build your query without having to type all the names in, but with some manual effort.
Start with "Select a.chapter"
Now perform another select on your data base as follows :
select ','|| column_name
from user_tab_cols
where table_name = your_real_table_name
and column_name <> 'CHAPTER';
now take the output from that, in a cut-and-paste manner and append it to what you started with. Now run that query. It should be what you asked for.
Ta-da!
Unless you have a very good reason to do so, you should not use SELECT * in queries. It will break your application every time the schema changes.