Skip to content
Advertisement

Tag: sql

SQL – How to use a value from INSERTed table

I am trying to insert a new location record in my db … and then reuse the value of the newly created id in a select statement’s where clause later on. But I’m getting a syntax error. Code: The error is “Must declare scalar variable” and it dies on there WHERE clause in the SELECT statement. I also tried something

How to get list of ids into separate column

Problem statement: I have a table master_tab which consist of two columns e_id and owner_id. I want to list down the e_id’s which belong to owner_id 72 and 73. There is another condition that analysis_comp flag should be 1 in the table transaction_tab. My attempt: Tool used: SQL Developer(18c) Current Output: Expected Output: Is it possible to get only the

How to write SQL statement to select for data broken up for each month of the year?

I am looking for a way to write an SQL statement that selects data for each month of the year, separately. In the SQL statement below, I am trying to count the number of instances in the TOTAL_PRECIP_IN and TOTAL_SNOWFALL_IN columns when either column is greater than 0. In my data table, I have information for those two columns (“TOTAL_PRECIP_IN”

PostgreSQL: Using CTE with IN

Learning CTE right now, the following query is super basic and it doesn’t really have any useful value but I don’t understand why it doesn’t work The error I’m getting is “ERROR: column “cte_actors” does not exist” Currently using postgres 14 and DBeaver Answer You need to SELECT from the CTE:

Insert row into an empty table with INSERT … SELECT … FROM command in SQL

I’m going to make a new table (PersonInformation) with columns of another one(Members) and some more columns like “Username”, “Password” and “PersonId”. The command I used is: ‘INSERT INTO myTable(Columns_in_PersonInformation…) SELECT (Columns_in_Members + new_columns) FROM Members, PersonInformation WHERE Members.id = PersonInformation.PersonId’ I have two problems, the first one when the PersonInformation table is empty. The result is “0 rows affected”

Pythonic way to optimize SQL VIEW count to extract information schema metadata from Snowflake

I have 12 VIEW tables in Snowflake and I would like to extract TABLE_NAME,CREATED,LAST_ALTERED from Snowflakes INFORMATION Schema for View tables, and also want to get row count for each 12 VIEW tables, along with metadata for Base table mentioned in below code.I was wondering if there is way get row count using below code for 12 VIEW tables or

Advertisement