473,396 Members | 2,002 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,396 software developers and data experts.

How to use JOIN to select data from multiple tables using only one query

This is my table

tblName

Pid PName Country
------------------------------------------------------------------
100 Shantosh India
102 Mukesh India
103 Rakesh India


and another table is

tbl item

Tid Pid Item
----------------------------------------------
1 100 scrow
2 100 bolt
3 100 Nutt
4 102 wood
5 102 Nutt


Now i want to result like that

Result by query

Pid PName item
----------------------------------------------------
100 Shantosh scrow
102 Mukesh wood
103 Rakesh Null
Jun 23 '07 #1
6 5653
Atli
5,058 Expert 4TB
Hi, and welcome to TSDN!

You could use JOIN to join your tables. That basicly searches for matching rows using the columns you specify in the ON clause and allows you to select from those rows only.
Specifying a LEFT JOIN will force the query to return all rows from the first table, returning NULL for those columns you selected from the second one and returned no values for that row.

For example:
Expand|Select|Wrap|Line Numbers
  1. SELECT n.Pid, n.PName, i.Item
  2. FROM tblName AS n
  3. LEFT JOIN tblItem AS i
  4.   ON n.Pid = i.Pid;
  5.  
P.S. I don't have what I need to test this query atm so please let me know if there are any problems.
Jun 23 '07 #2
Atli
5,058 Expert 4TB
I have edited the thread's title to better describe it's contents.
Please read the Posting Guidlines before posting

Moderator
Jun 23 '07 #3
hi thanks for reply
i try this but not working.

i want to results like i menssion in my query.

have u got this result.

Thanks
Jul 5 '07 #4
r035198x
13,262 8TB
hi thanks for reply
i try this but not working.

i want to results like i menssion in my query.

have u got this result.

Thanks
What happens when you try that? Does it give an error or does it return the wrong results?
Jul 5 '07 #5
What happens when you try that? Does it give an error or does it return the wrong results?
It's not give an error but not give results which i want.
i want to result like i mansion in my thread .
Jul 19 '07 #6
mwasif
802 Expert 512MB
No one can understand what do you mean by "but not give results which i want.". It is always better to show the result you are getting.

You have 3 records for 'Shantosh' in tblItem. Which result do you want, scrow, bolt or Nutt?
Jul 19 '07 #7

Sign in to post your reply or Sign up for a free account.

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: TeleTech1212 | last post by:
I am trying to select specific columns from multiple tables based on a common identifier found in each table. For example, the three tables: PUBACC_AC PUBACC_AM PUBACC_AN each have a...
7
by: Pino | last post by:
Hi, to everybody, let's consider this scenario: you have 1 data-table and 10 dictionary-tables; the data-table has 5 million records and 30 columns, 10 of these columns have a foreign-key to the...
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...
7
by: Shanimal | last post by:
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; ...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
5
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
5
by: jim | last post by:
Hi, I've browsed several posts, but still haven't found the answer I'm looking for. I have one table (A) that contains a list of values I want to return. I have two other tables (B) and (C)...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...

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.