473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to join 2 queries into 1

I would like to know how to join 2 queries so that the results of these
2 queries show up in the same query:

SELECT b.bios_serial_number FROM bios b:
SELECT s.system_name FROM system s;

Basically I want to create a report that includes both system name and
serial number. I'm new to this and none of the JOIn documentation was
clear to me.

thanks!
PS

Mar 10 '06 #1
7 4141
Shanimal wrote:
I would like to know how to join 2 queries so that the results of these
2 queries show up in the same query: SELECT b.bios_serial_number FROM bios b:
SELECT s.system_name FROM system s; Basically I want to create a report that includes both system name and
serial number. I'm new to this and none of the JOIn documentation was
clear to me. thanks!
PS

We would need to see what columns are in each table so that we can see the
relationship between the 2 tables.

Example:
bios
systemid bios_serial_number
123 abc123456
124 abd345678

System
systemid system_name
123 somesystemname
124 someothername

select s.system_name,b.bios_serial_number from bios b, system s
where b.???? = s.????;

s.???? and b.???? should contain a the same information pertaining to
system - like a systemID in the above example

Mar 10 '06 #2
"Shanimal" <sh******@att.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Basically I want to create a report that includes both system name and
serial number. I'm new to this and none of the JOIn documentation was
clear to me.


It's a lot of work, and probably not the best use of your time or ours, to
cover the basics on a newsgroup, when so many other materials already exist
for this purpose.

Find another document or tutorial on joins. Keep reading until you
understand joins. Joins are a fundamental concept in SQL, as fundamental as
loops are in most other programming languages. You must understand joins,
or else you might as well be using a spreadsheet.

Try a Google search for "sql join tutorial" and read a few of the free
tutorials available. Or pick up an introductory book like "SQL for Dummies"
(I'm not trying to be condescending, it's really a good book).

Regards,
Bill K.
Mar 10 '06 #3
Bill Karwin wrote:
[snip] Or pick up an introductory book like "SQL for Dummies"
(I'm not trying to be condescending, it's really a good book).
I concur.
Regards,
Bill K.

Mar 10 '06 #4
noone-

Thanks for trying to help!

I don't think there is a relation between the two tables. The BIOS
table holds the following info (columns):

bios_id
bios_uuid
bios_description
bios_manufacturer
bios_serial_number
bios_sm_bios_version
bios_version
bios_asset_tag
bios_timestamp
bios_first_timestamp

The BIOS doesn't include the system name.

The system table holds the following information (columns):

system_num_processors
system_memory
system_build_number
net_ip_address
system_uuid
net_domain
net_user_name
net_client_site_name
net_domain_controller_address
net_domain_controller_name
system_model
system_name
system_part_of_domain
system_primary_owner_name
system_system_type
system_id_number
system_vendor
time_caption
time_daylight
system_boot_device
system_os_type
system_os_name
system_country_code
system_description
system_organisation
system_language
system_registered_user
system_serial_number
system_service_pack
system_version
system_windows_directory
audit_type
firewall_enabled_domain
firewall_disablenotifications_domain
firewall_donotallowexceptions_domain
net_domain_role
firewall_enabled_standard
firewall_disablenotifications_standard
firewall_donotallowexceptions_standard
virus_manufacturer
virus_version
virus_name
virus_uptodate
date_virus_def date
date_system_install
system_timestamp
system_first_timestamp

The system table doesn't include any bios serial number.

I want the query to return the system name and bios serial number. So
far I can get one of the other, but not both together. What good is
getting a list of serial numbers for computers when you don't have a
computername?

I've read a couple of tutorials, I've searched the My SQL website and
google, the answer isn't clear. This is why I'm posting here, it's a
legit request. I'm not going to sign up for a class on this when the
newsgroup is readily avaialable and there are people out there willing
to help (there are)!

Mar 10 '06 #5
"Shanimal" <sh******@att.net> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
I don't think there is a relation between the two tables.


You said you want both the system name and the bios serial number. Which
bios serial number goes with which system name?

This is the concept of a join: to express the criteria for matching rows of
one table to rows of another table. How they match up is the relationship
between the two tables.

It's possible that you do not have the right information in these two tables
to express the relationship. This would naturally make it hard to envision
the join criteria.

For instance, as in noone's example, it is typical that there is a column
that appears in both tables. Where you find identical values in that column
in both tables, that's the definition of rows that match. But you don't
seem to have that column in common between the two tables, so you may have
no expressable relationship given the current state of the data.

The other possibility is that you need a third table to express the
relationship. This is useful if one bios can match multiple systems, and
also one system can match multiple bios's. This is called a "many-to-many"
relationship. You'd need to join this third table to both the bios table
and the system table in one query, in order to match up all the entries.

Regards,
Bill K.
Mar 10 '06 #6

Bill Karwin wrote:
"Shanimal" <sh******@att.net> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
I don't think there is a relation between the two tables.


You said you want both the system name and the bios serial number. Which
bios serial number goes with which system name?

This is the concept of a join: to express the criteria for matching rows of
one table to rows of another table. How they match up is the relationship
between the two tables.

It's possible that you do not have the right information in these two tables
to express the relationship. This would naturally make it hard to envision
the join criteria.

For instance, as in noone's example, it is typical that there is a column
that appears in both tables. Where you find identical values in that column
in both tables, that's the definition of rows that match. But you don't
seem to have that column in common between the two tables, so you may have
no expressable relationship given the current state of the data.

The other possibility is that you need a third table to express the
relationship. This is useful if one bios can match multiple systems, and
also one system can match multiple bios's. This is called a "many-to-many"
relationship. You'd need to join this third table to both the bios table
and the system table in one query, in order to match up all the entries.

Regards,
Bill K.


Bill-

Thanks for taking the time to explain this to me. It totally makes
sense now, after reading just the first paragraph you posted. I was
missing the concept now I get it. As you mentioned, there has to be
some relationship connecting them. Within the system table I found that
system_id_number is the same as the bios serial number so I can figure
out the join concept and get the info that I need.

thanks again!
PS

Mar 10 '06 #7
Shanimal wrote:
Bill Karwin wrote:
"Shanimal" <sh******@att.net> wrote in message
news:11*********************@i40g2000cwc.googleg roups.com...
I don't think there is a relation between the two tables.


You said you want both the system name and the bios serial number. Which
bios serial number goes with which system name?

This is the concept of a join: to express the criteria for matching rows of
one table to rows of another table. How they match up is the relationship
between the two tables.

It's possible that you do not have the right information in these two tables
to express the relationship. This would naturally make it hard to envision
the join criteria.

For instance, as in noone's example, it is typical that there is a column
that appears in both tables. Where you find identical values in that column
in both tables, that's the definition of rows that match. But you don't
seem to have that column in common between the two tables, so you may have
no expressable relationship given the current state of the data.

The other possibility is that you need a third table to express the
relationship. This is useful if one bios can match multiple systems, and
also one system can match multiple bios's. This is called a "many-to-many"
relationship. You'd need to join this third table to both the bios table
and the system table in one query, in order to match up all the entries.

Regards,
Bill K.

Bill-

Thanks for taking the time to explain this to me. It totally makes
sense now, after reading just the first paragraph you posted. I was
missing the concept now I get it. As you mentioned, there has to be
some relationship connecting them. Within the system table I found that
system_id_number is the same as the bios serial number so I can figure
out the join concept and get the info that I need.

thanks again!
PS

Based on this statement:
"Within the system table I found that system_id_number is the same as
the bios serial number so I can figure out the join concept and get the
info that I need."

now you can just

select syste_name,system_id_number as bois_serial_number from system;

This query "renames" the column name at select time to be whatever you
want it to be...

without having to do a join at all... the purpose of a join is retrieve
non-repeating data from the 2(or more) tables.
Mar 11 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
1
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes...
1
by: Beachvolleyballer | last post by:
hi there anyone had an idea to join following 2 queries to 1???? ----- QUERY 1 --------------------------------------------- SELECT TMS_CaseF_2.Name AS TCDomain_0, TMS_CaseF_3.Name AS...
2
by: Greg Stark | last post by:
I find I often want to be able to do joins against views where the view are aggregates on a column that has an index. Ie, something like SELECT a.*, v.n FROM a JOIN (select a_id,count(*) as n...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
2
by: HS Hartkamp | last post by:
Hi all, I have a table with analysis-results for various months. An item can -for a particular month- have the result 'list1', 'list2' or 'list3' depending on the result of the analysis. ...
9
by: Alan Lane | last post by:
Hello world: Background: Yesterday, January 21, Doug Steele was kind enough to help me out on a Left Join problem. I was trying to return all stores and their Gross Adds for December, 2004...
3
by: mariohiga | last post by:
Hello I've a really big doubt :) I've this two alternatives SELECT * FROM T1 a INNER JOIN T1 b ON a.F1 = b.F1 AND a.F2 = 1 SELECT *
14
by: cjakeman | last post by:
Hi, Solved a little mystery yesterday when I built a form that combined 2 tables with a 1:M relationship and relational integrity. All the correct data was visible on the form but, if I tried to...
2
by: frederikengelen | last post by:
Hello all, We are seeing strange behaviour for queries on a table we need to convert data from. We try to find out whether table A(B_CONV_ID) contains data that does not exists in table...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.