0

Get results from two different tables using a complex query or procedure. Read the details please.

I have two tables. 1. employees(id, name) 2. documents(id, employee_id, file_path, document_type[PASSPORT, DL, PAN_CARD]) I want to list these details like this ------------------------------------------------- | Employee | Passport | DL | PAN_CARD| | ABC | 1 | 1 | 0 | | AFG | 0 | 1 | 1 | | XYZ | 2 | 1 | 1 | ------------------------------------------------- *Here integer value denotes the number of scanned documents saved with a employee_id in 'documents' table. *Sometimes we have to scan a document from both side or multiple pages. So multiple documents with same 'document_type' and 'employee_id' can exists(Example 'XYZ' with 2 passport document).

15th Nov 2016, 11:33 PM
Satyendra Chaudhary
Satyendra Chaudhary - avatar
6 Réponses
+ 1
do it with inner join
16th Nov 2016, 12:33 AM
Maurizio Urso
Maurizio Urso - avatar
+ 1
you should use a 3th table like documentOfEmpl
16th Nov 2016, 12:43 AM
Maurizio Urso
Maurizio Urso - avatar
+ 1
the table documents must have only the type of document with these columns: idDoc desc example: 0 1 passport id card
16th Nov 2016, 12:46 AM
Maurizio Urso
Maurizio Urso - avatar
+ 1
the table documentOfEmpl have these columns: employe,typeDocument,file_path
16th Nov 2016, 12:49 AM
Maurizio Urso
Maurizio Urso - avatar
+ 1
SELECT employees.name, documents.PASSWORD,documents.DL,documents. PAN_CARD FROM documents, employees WHERE employees.id=documents.employees_id ORDER BY employees.id I have assume that id colume in employees table is employees id. If they are not please tell me which colume in both of tables are same. If their is no colume same create a table with employees id in employees table. Remember you have to create a link between two tables. If there is no link how you perform search query.
16th Nov 2016, 1:54 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
That won't work because here is one to many relationship between both tables and also results from table documents needs to be grouped by document_type.
16th Nov 2016, 12:41 AM
Satyendra Chaudhary
Satyendra Chaudhary - avatar