Thursday 15 May 2014

Oracle SQL Query to get missing date from two joined tables -


I'm trying to write Oracle SQL query and I'm unable to get the right result.

For the tables below, I would first like to get all the records from DEVICE where DEVICE.MODEL = 'UNITA' and for those results, give me a DEVICE. CUSTOMER_ID has no record where PROFILE is located. TYPE = 'TEST' CUSTOMER_ID is joining both tables Any ideas about preparing this query?

  table device: id - sequence primary key (NUMBER (10)) generated DEVICE_NUMBER - unique (varchar) CUSTOMER_ID (varchar) model (varchar) table profile: ID - Order generated primary key (NUMBER (10)) CUSTOMER_ID (varchar) TYPE (varchar)    

if i need , Then this should do the trick:

  SELECT d.ID, d.evice_number, d.Customer_ID, d.model, device DE LEFT JOIN profile p current D.Customer_ID = p. Customer_ID WHERE d.Model = 'UNITA' and (PIID is zero or P. type = 'tes   

This works because of the left left , which will give the profile.id if a match profile < / Code> line customer_id . If there is a matching line, then the test for Profile.Type = 'TEST' will determine what is included.

In a SQL Belal field, enter profile.id and profiles. Type results in values ​​because I think they explain things more clearly.


Appendix : Some confusion over my share of needs; This query may be close to what it needs:

  SELECT d.ID, d.Device_Number, d.Customer_ID, d.Model, p.id AS PID, p. D.Customer_ID = p.Customer_ID and p.Type = Profile PD on 'Exam' Model = 'unitata' and piid is null    

No comments:

Post a Comment