Simple SQL Query question
Discussion
I have a database (DB_Service) with multiple tables in it. The data I want 'software version installed' is in the table SOFTWARE_INVENTORY. So, the query is:
select * from SOFTWARE_INVENTORY;
However, this table only contains a device ID to which the data belongs. I need to match the device ID to a username. That exists in another table 'DEVICE'. So, the query is:
select * from DEVICE;
But this gives me two separate sets of data, really I want both sets of data merged so I can export to Excel and filter/sort.
What query could I use to extract the data from both tables and merge them into one CSV file? Then I could sort on software version and it would show the associated device ID and username?
select * from SOFTWARE_INVENTORY;
However, this table only contains a device ID to which the data belongs. I need to match the device ID to a username. That exists in another table 'DEVICE'. So, the query is:
select * from DEVICE;
But this gives me two separate sets of data, really I want both sets of data merged so I can export to Excel and filter/sort.
What query could I use to extract the data from both tables and merge them into one CSV file? Then I could sort on software version and it would show the associated device ID and username?
LarryUSA said:
I have a database (DB_Service) with multiple tables in it. The data I want 'software version installed' is in the table SOFTWARE_INVENTORY. So, the query is:
select * from SOFTWARE_INVENTORY;
However, this table only contains a device ID to which the data belongs. I need to match the device ID to a username. That exists in another table 'DEVICE'. So, the query is:
select * from DEVICE;
But this gives me two separate sets of data, really I want both sets of data merged so I can export to Excel and filter/sort.
What query could I use to extract the data from both tables and merge them into one CSV file? Then I could sort on software version and it would show the associated device ID and username?
Select *,B.* from SOFTWARE_INVENTORY Aselect * from SOFTWARE_INVENTORY;
However, this table only contains a device ID to which the data belongs. I need to match the device ID to a username. That exists in another table 'DEVICE'. So, the query is:
select * from DEVICE;
But this gives me two separate sets of data, really I want both sets of data merged so I can export to Excel and filter/sort.
What query could I use to extract the data from both tables and merge them into one CSV file? Then I could sort on software version and it would show the associated device ID and username?
inner join DEVICE B on A.DEVICE_ID = B.DEVICE_ID
fbc said:
anxious_ant said:
Select *,B.* from SOFTWARE_INVENTORY A
inner join DEVICE B on A.DEVICE_ID = B.DEVICE_ID
Just to expand on that slightly, in the inner join statement, field A.DEVICE_ID is the field in the SOFTWARE_INVENTORY table containing the Device ID, and likewise B.DEVICE_ID is the field in the DEVICE table containing the Device ID. These fields may have differing names in the respective tables (they shouldn't, but they might).inner join DEVICE B on A.DEVICE_ID = B.DEVICE_ID
LarryUSA said:
Wow! Thanks anxious_ant, that worked just with a copy and paste command. I knew PH would come up with the answer!
The icing on the cake would be when I select all the data, right click and 'Save Results As...' if it would export the column headings! But it's no big deal...
If you are using SQL Management Studio right click on the grid output and select "Copy with headers" and paste it into Excel then save as CSV. The icing on the cake would be when I select all the data, right click and 'Save Results As...' if it would export the column headings! But it's no big deal...
anxious_ant said:
LarryUSA said:
Wow! Thanks anxious_ant, that worked just with a copy and paste command. I knew PH would come up with the answer!
The icing on the cake would be when I select all the data, right click and 'Save Results As...' if it would export the column headings! But it's no big deal...
If you are using SQL Management Studio right click on the grid output and select "Copy with headers" and paste it into Excel then save as CSV. The icing on the cake would be when I select all the data, right click and 'Save Results As...' if it would export the column headings! But it's no big deal...
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff





: