473,839 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_n umber 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 4164
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_n umber 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_num ber
123 abc123456
124 abd345678

System
systemid system_name
123 somesystemname
124 someothername

select s.system_name,b .bios_serial_nu mber 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.n et> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.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_descriptio n
bios_manufactur er
bios_serial_num ber
bios_sm_bios_ve rsion
bios_version
bios_asset_tag
bios_timestamp
bios_first_time stamp

The BIOS doesn't include the system name.

The system table holds the following information (columns):

system_num_proc essors
system_memory
system_build_nu mber
net_ip_address
system_uuid
net_domain
net_user_name
net_client_site _name
net_domain_cont roller_address
net_domain_cont roller_name
system_model
system_name
system_part_of_ domain
system_primary_ owner_name
system_system_t ype
system_id_numbe r
system_vendor
time_caption
time_daylight
system_boot_dev ice
system_os_type
system_os_name
system_country_ code
system_descript ion
system_organisa tion
system_language
system_register ed_user
system_serial_n umber
system_service_ pack
system_version
system_windows_ directory
audit_type
firewall_enable d_domain
firewall_disabl enotifications_ domain
firewall_donota llowexceptions_ domain
net_domain_role
firewall_enable d_standard
firewall_disabl enotifications_ standard
firewall_donota llowexceptions_ standard
virus_manufactu rer
virus_version
virus_name
virus_uptodate
date_virus_def date
date_system_ins tall
system_timestam p
system_first_ti mestamp

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.n et> wrote in message
news:11******** *************@i 40g2000cwc.goog legroups.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.n et> wrote in message
news:11******** *************@i 40g2000cwc.goog legroups.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_numbe r 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.n et> wrote in message
news:11****** *************** @i40g2000cwc.go oglegroups.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
relationshi p. 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"
relationshi p. 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_numbe r 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_numbe r 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,syst em_id_number as bois_serial_num ber 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
3078
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 solve my problem. I'll turn to MySQL doc after getting through this pressing project. Thanks a lot Roger! Babale -----Urspr=FCngliche Nachricht-----
1
3463
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 in trees which form parent-child relationships, sort of like newsgroups. For example, the parent_id field points to another element. Indent_level is there for denormalization purposes, to avoid costly recursive issues in querying. The...
1
2273
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 TCDomain_1, TMS.CaseF.Name AS TCFolder_2, TMS_CaseF_1.Name AS TCFolder_3,
2
3682
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 group by a_id) as v USING (a_id) where there's an index on b.a_id. assume there are other tables being joined so I can't just move the aggregate to the outermost layer.
3
23103
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 he doesn't know how to do that, or even if he can, and i don't have to time to learn DB2 from scratch right now. The following SQL Query is a trimmed sample of the full View (i.e. Logical) definition - and i would create it on an SQL based...
2
3361
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. Next, I want to get an insight in how the various items change over time. For that, I compare the results of one month with the results of another month. The form in which I want this is a cross-tab-query with one month as a row-header and another...
9
3215
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 (even though some of them had no Gross Adds for that month). My query would only show the non-zero GA stores. Doug stated "It's because of the Where clause. The stores which don't have any records for the period in question are being eliminated...
3
1523
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
2502
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 edit any of the fields, the PC bleeped. Seems it was due to the query the form was based on. Again, editing any of the fields of the query caused the PC to bleep.
2
2253
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 B(CONV_ID). We expect that there is data missing in table B, thus finding a positive number of records. There are two tables, A and B.
0
9855
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10907
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10647
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10293
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3133
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.