Simple SQL query help

Status
Not open for further replies.
Hi Guys,

I have 2 tables one is a list of every print job it is like:

Code:
Job_ID,Computer_Name,Printer_ID

The other is the list of printers it is like:

Code:
Printer_ID,Printer_Name

I need to know which unique PCs have used each unique printer so I need to return something like:

Code:
Printer_Name,Computer_Name1,Computer_Name2,Computer_Name3
 
D

Deleted member 43669

Guest
Code:
select distinct printer_name, computer_name
from            printers
natural join    print_jobs

if your db does not support natural join,

Code:
select distinct printer_name, computer_name
from            printers
join            print_jobs using (printer_id)

if it does not support using,

Code:
select distinct printer_name, computer_name
from            printers
join            print_jobs on printers.printer_id = print_jobs.printer_id

From the results, create the list as you prefer. Depending on your RDBMS, you might be able to:

Code:
select   printer_name, concat(computer_name, ',')
from     printers
join     print_jobs on printers.printer_id = print_jobs.printer_id
group by printer_name

, check your RDBMS name if there's an aggregate concatenation function to use as 'concat'.
 
Status
Not open for further replies.