Category "join"

SQL Query with 2 conditions but from different tables

I have the below query that has only one condition, which is if the companies are included in the table, then mark them as "Yes" under [Competitor] column, if t

SQL query question, how to make a query that outputs all entries of two tables

I have two tables, CITIES and FLIGHTS: CITIES id name 1 New York 2 Paris 3 Tokyo 4 Amsterdam FLIGHTS id departure_id arrival_id 1 1 2 2 1 3 3 2 3 4 2 4 I ne

MantToMany - Cannot add or update a child row: a foreign key constraint fails

I am trying to create Many to Many relationship and save some data to database. I have entities: @Data @AllArgsConstructor @NoArgsConstructor @Entity public cla

SQL returning all rows and count

I have 3 tables, Property managers, Addresses and Units. I'm trying to get all the rows using the aggregate function COUNT, but it only returns 1 row. I want to

How to Join two tables and update a column?

I have two tables as below TableA TableB ID1 ID2 ID1 ID3 1 X 1 X 2 NULL 2 A 3 (NULL) 3

How do i join on null in two table in sql? inner join, left,right,full n cross join -- Interview Question Tech Mahindra

Create table TechM ( id int ) ; select * from TechM insert into TechM values (1), (1), (1), (2), (3), (null) ; Create table TechN ( id int ) ; select * from Tec

Is there a way to create an inline anonymous table in Oracle like in PostgreSQL?

I have a postgres query that creates an anonymous table from string values and then joins on them like this: select distinct anon_table.string1,

is there a way to extract duplicated row value in sql as the key/grouping value?

I have following two tables users id | name 1 | john 2 | ada events id | content | userId 1 | 'applied' | 1 2 | 'interviewed| 1 What would be the

SQL - How to join tables with dates to get overall view of ALL dates

Using a bespoke ERP system with T & A built in. Table 1 has dates with holidays types i.e. bank holidays, user booked holidays - and a user id. Table 2 has

complex UPDATE query in psycopg2

I've stumbled upon an interesting problem while trying to compose an SQL query using psycopg2.sql I have a function that takes in some kind of data in a dict fo

What is the optimized/best way to retrieve data from two tables?

I have two tables: post table: |post_id | post_title | +--------+------------+ | 1 | Post 1 | | 2 | Post 2 | | 3 | Post 3 | post_cre

Can I nest a select statement within an IF function in SQL?

Using Teradata.. I want to write a query that joins table 1 and table 2 on item code to the location in table 2. There are multiple locations per item code and

Querying pivot table to return a list of referred rows

I have these 6 tables and query which returns everything I want, but I want to add a new pivot table, so I can get a list of rows linked to it. Query: SELECT DI

Why does my table join return values I didn't specify?

I am attempting to join two tables to create a visualization that shows the relationship between weight, BMI, and total steps using the following code: SELECT

What is wrong with this inner join sql query

I want to export some data from the DB. Basically what I want to say is this: 1- Select mbr_name from the members table 2- Choose the ones that exist at the cou

Generate random pairs SQL

Suppose we have these two tables. TABLE1: |column_1 | ... | -------------------- | 'a' | ... | | 'b' | ... | | 'c' | ... | |

I connot able to filter the current user record using c# and MS Access DB

I connot able to filter the current user record. I want to display the data of current user only. But I did not understand how to handl query. here is the ss of

Impala compare consecutive rows and insert identical row if there are no values

I have a table that gives me data every month and I need that range of time. I noticed that sometimes I don't have data for 3/4 month but I need to duplicate th

Impala compare consecutive rows and insert identical row if there are no values

I have a table that gives me data every month and I need that range of time. I noticed that sometimes I don't have data for 3/4 month but I need to duplicate th

Join tables on dates, with dirty date field

In AWS Athena, I am trying to join two tables in the db using the date, but one of the tables (table2) is not clean, and contains values that are not dates, as