Bloomberg LP Interview Question for Software Engineer / Developers


Team: Supply Chain
Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
7
of 9 vote

SELECT Cust_name from Customers
where
Cust_id NOT in (Select Cust_id from Orders)

--Assuming cust_id is primary key in customers and foreign key in Orders

- Hank Readen December 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
5
of 9 vote

Best way to find this information is using left join

Select Cust_Name from
Customers C
LEft Join Orders O On C.Cust_id = O.Cust_id
Where O.Cust_id is null

- Jai December 07, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this doesn't make sense to me, your foreign key O.Cust_id should never be null, that's violating referential integrity, furthermore, C.Cust_id should also never be null if it's the primary key of the customer table

- dereknheiley December 11, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Left join returns null on the joined table where there are no matches

SELECT Cust_Name, Order_Name
FROM Customers C
LEFT JOIN Orders O ON C.Cust_id = O.Cust_id
WHERE Order_Name is null

- Anonymous December 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Please remember O.Cust_id is foreign key in Orders table and foreign key can be nulls too. In this relation with left outer join it we are not checking null primary keys of customer table rather we are checking in customers who don't have records in orders table which is fine so will return null values..

- Jai December 19, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select * from customer where customer_id not in (select customer_id from order );

- Anonymous June 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Both of these work. But thinking what is more efficient . Thoughts?

select * from customer
where cust_id not in (select cust_id from order1)

select * from customer c1
where not exists (select * from order1 o1 where o1.cust_id = c1.cust_id)

- Anonymous March 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select * from customer
where cust_id not in (select cust_id from order1)

select * from customer c1
where not exists (select * from order1 o1 where o1.cust_id = c1.cust_id)

- Engineer1111 March 15, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select c.cust_id
from customer c
minus
select o.cust_id
from orders o;

/

select cust_id
from customer
where cust_id not in (select cust_id from orders);

select c.cust_id
from customer c
,orders o
where o.cust_id(+) = c.cust_id
and o.cust_id is null;

- Naresh August 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select c.cust_id
from customer c
minus
select o.cust_id
from orders o;

/

select cust_id
from customer
where cust_id not in (select cust_id from orders);

select c.cust_id
  from customer c
      ,orders   o
where o.cust_id(+) = c.cust_id
  and o.cust_id is null;

- Naresh August 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select c.cust_id
   from customer c
   minus
   select o.cust_id 
   from orders o;
  
 /
 
 select cust_id
   from customer
where cust_id not in (select cust_id from orders);

select c.cust_id
  from customer c
      ,orders   o
where o.cust_id(+) = c.cust_id
  and o.cust_id is null;

- Naresh August 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote
{{{a}} - Anonymous August 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

select c.cust_id
   from customer c
   minus
   select o.cust_id 
   from orders o;

select cust_id
   from customer
where cust_id not in (select cust_id from orders);

select c.cust_id
  from customer c
      ,orders   o
where o.cust_id(+) = c.cust_id
  and o.cust_id is null;

- Anonymous August 12, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Select cust_name from Customers a where (Select count(*) from Orders b
where a.cust_id=b.cust_id)=0;

The inner query will calculate the number of orders for a particular cust_id....
An output of 0 will indicate that the customer never ordered anything..

- Arupam February 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Why do you have to use sub queries when you can do that with left outer join?

- Jai February 04, 2015 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More