Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3490578
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:32:00+00:00 2026-05-18T11:32:00+00:00

I am looking to get the first date with the customer and item description

  • 0

I am looking to get the first date with the customer and item description from the following example table

To create my example

CREATE TABLE cust
(
CUSTNO int,
ENAME varchar(50)
)

CREATE TABLE orders
(
CUSTNO int,
Description varchar(50),
ORDERDATE date
)

INSERT INTO cust VALUES (7369, 'SMITH');
INSERT INTO cust VALUES (7499, 'ALLEN');
INSERT INTO cust VALUES (7521, 'WARD');
INSERT INTO cust VALUES (7566, 'JONES');
INSERT INTO cust VALUES (7654, 'MARTIN');
INSERT INTO cust VALUES (7698, 'BLAKE');
INSERT INTO cust VALUES (7782, 'CLARK');
INSERT INTO cust VALUES (7788, 'SCOTT');
INSERT INTO cust VALUES (7839, 'KING');
INSERT INTO cust VALUES (7844, 'TURNER');
INSERT INTO cust VALUES (7876, 'ADAMS');
INSERT INTO cust VALUES (7900, 'JAMES');
INSERT INTO cust VALUES (7902, 'FORD');
INSERT INTO cust VALUES (7934, 'MILLER');

INSERT INTO orders VALUES (7782, 'Something','17-DEC-1980');
INSERT INTO orders VALUES (7782, 'Something else', '17-DEC-2000');
INSERT INTO orders VALUES (7900, 'Something', '17-DEC-1980');
INSERT INTO orders VALUES (7900, 'Something else','17-DEC-1990');
INSERT INTO orders VALUES (7934, 'Something','17-DEC-1980');

Was trying something like this

  select [ENAME],[cust].[CUSTNO], MIN([ORDERDATE]),[Description]
  from [cust],[orders]
  where [cust].[CUSTNO]=[orders].[CUSTNO]
  group by [cust].[CUSTNO],[ENAME],[Description]

My problem is this returns too many rows. I just want to see each customer and then list there first date (blank or null if there is no order).

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:32:00+00:00Added an answer on May 18, 2026 at 11:32 am
      SELECT c.[ENAME],c.[CUSTNO], o.[orderdate], o.[Description] 
       FROM  cust  c
      LEFT JOIN orders o 
        ON c.custNo = o.custno 
      LEFT JOIN 
            ( SELECT   custno, min(orderdate) orderdate 
                FROM [orders] 
                GROUP BY custno)  mo 
        ON mo.orderdate = o.orderdate 
            AND mo.custno = o.custno 
    

    You need the left joins to get the order if one exists but still get the customer if no orders exist. @conrad Frix’s solution will work as well, but I incuded this in case you use a database that doesn’t accept the with statement.

    In the future, you should stop writing implict joins (using a comma to separate the tables and putting the join conditions inteh where clause). They are a bad programming techinique and contribute to why you don’t understand joins correctly (or you would have known to use a left join).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.