473,473 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Most Basic SQL Question

3 New Member
Hi, Am starting to teach myself SQL. I cannot figure out how to do the most simple of queries, and it is driving me nuts. Here's the basic scenario:

Table: Customer
custid
firstname
lastname

Table: Transactions
custid
transdate
transamount

I want a query which will display ALL customers and any associated transactions. However, the query I used (below) only returns the customer if there is a transaction for it. For customers with no transactions, they are not being listed and I need help to show me how to structure the query to that the listing of the master table is not dependent on there being any child records in existence.

Expand|Select|Wrap|Line Numbers
  1. select customer.custid, customer.firstname, customer.lastname, transactions.transdate, transactions.transamount 
  2. from customer, transactions where customer.custid=transactions.custid
Please tell me where I am going wrong!!!
Jul 1 '07 #1
3 1083
bartonc
6,596 Recognized Expert Expert
You'll find SQL experts in the "Database" section under the "Forums" tab, above. There may not be an SQL expert who checks these Misc. Q.s, so try group that most closely matches the tools that you are using (the most popular RDBMSs are listed there).

Good luck.
Jul 1 '07 #2
bartonc
6,596 Recognized Expert Expert
Hi, Am starting to teach myself SQL. I cannot figure out how to do the most simple of queries, and it is driving me nuts. Here's the basic scenario:

Table: Customer
custid
firstname
lastname

Table: Transactions
custid
transdate
transamount

I want a query which will display ALL customers and any associated transactions. However, the query I used (below) only returns the customer if there is a transaction for it. For customers with no transactions, they are not being listed and I need help to show me how to structure the query to that the listing of the master table is not dependent on there being any child records in existence.

Expand|Select|Wrap|Line Numbers
  1. select customer.custid, customer.firstname, customer.lastname, transactions.transdate, transactions.transamount 
  2. from customer, transactions where customer.custid=transactions.custid
Please tell me where I am going wrong!!!
Have you tried just leaving off the where clause?
Jul 1 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
You don't say what database system you are using so the syntax will vary a bit. You will need to use a LEFT JOIN or a LEFT OUTER JOIN. Something like the following

Expand|Select|Wrap|Line Numbers
  1. SELECT customer.custid, customer.firstname, customer.lastname, transactions.transdate, transactions.transamount 
  2. FROM customer LEFT JOIN transactions 
  3. ON customer.custid = transactions.custid
  4.  
However, as I said the syntax will vary. If you tell us the database system you are using we can try to help further.
Jul 2 '07 #4

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

Similar topics

7
by: http://vmdd.tech.mylinuxisp.com/catalog/ | last post by:
After having seen my co-worker reinventing the wheel when he busily labored to build MS Access framework, I want to share my perspective. Having experienced with Access, Visual Basic, Visual...
27
by: Servé Lau | last post by:
in what fields of computing is C used the most nowadays? embedded, scientific, applications? What?
4
by: Ramesh | last post by:
hi, Let me ask some basic questions. Can anybody explain me about the following questions: 1. When we have to create sn key? Whenever we compiled Component we have to create or it is a one time...
13
by: Pete | last post by:
I'm cross posting from mscom.webservices.general as I have received no answer there: There has been a number of recent posts requesting how to satisfactorily enable BASIC authorization at the...
5
by: Aussie Rules | last post by:
Hi, Having a mental block on this one. Have done it before but can't rack my brain on how... I have an object, with a bunch on property, and I add that object to a combo box. I want the...
4
by: Sector 7G | last post by:
I'm working with a SQL query for a Human Resources database. Its intended purpose is to find all the paycheck records with a check date (prckhist.chkdate ) more recent than eleven days past the...
4
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these...
3
by: kerry2807 | last post by:
Hi, I posted this in 'misc questions' and was directed here. Am starting to teach myself SQL. I cannot figure out how to do the most simple of queries, and it is driving me nuts. Here's the basic...
3
by: Scott Stark | last post by:
Hello, I'm trying to get a better handle on OOP programming principles in VB.NET. Forgive me if this question is sort of basic, but here's what I want to do. I have a collection of Employee...
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...
1
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.