JOIN SQL Query by date

Thanks a lot...here is to my final question:

I have three tables with the following columns:

  1. Clients:

Client ID First name Last name

  1. Transactions:

Trans ID ClientID RepresentativeID OrderDate

  1. Representatives:

Representative ID First name Last name

I need to display all of the transactions information, with the representative name and client name that occurred in a specific date. Is this query right?

SELECT * 
FROM [Transactions], Clients.first name, Clients.last name,     Representatives.first name, Representatives. last name
 INNER JOIN [Clients]
 ON Transactions.ClientID= Clients.Client ID
 INNER JOIN [Representatives]
 ON Transactions.RepresntativeID = Representatives.Represntative ID
 WHERE Transactions.OrderDate BETWEEN '1996-09-18' AND '1996-11-27';

Is that right or did i get all wrong?

Answers


WHERE go after ON and before ORDER BY

also the ; go at the end not in the middle

SELECT * 
FROM [Orders] 
JOIN [Customers]
  ON Orders.CustomerID = Customers.CustomerID
WHERE Orders.OrderDate BETWEEN '1996-09-18' AND '1996-11-27'
ORDER BY Customers.CustomerName;

SELECT Clients.[first NAME] AS ClientFirstName
      ,Clients.[last NAME] AS ClientLastName
      ,Representatives.[first NAME] AS RepresentativesFirstName
      ,Representatives.[last NAME] AS RepresentativesLastName
      ,Transactions.*
FROM [Transactions]
INNER JOIN [Clients]
    ON Transactions.ClientID = Clients.Client ID
INNER JOIN [Representatives]
    ON Transactions.RepresntativeID = Representatives.Represntative ID
WHERE Transactions.OrderDate BETWEEN '1996-09-18'
        AND '1996-11-27';

What you expected outcome columns should put it to SELECT. From is your table or dataset.Also, you can use alias to simplify the SQL like below.

SELECT c.[first NAME] AS ClientFirstName
      ,c.[last NAME] AS ClientLastName
      ,r.[first NAME] AS RepresentativesFirstName
      ,r.[last NAME] AS RepresentativesLastName
      ,t.*
FROM [Transactions] t
INNER JOIN [Clients] c
    ON t.ClientID = c.Client ID
INNER JOIN [Representatives] r
    ON t.RepresntativeID = r.Represntative ID
WHERE t.OrderDate BETWEEN '1996-09-18'
        AND '1996-11-27';

Need Your Help

help with rails render action vs routing

ruby-on-rails ruby routing controller render

I was using some image cropping example that I found online and now I got confused. There is actually no "crop" method in my controller. Instead (following the guide) I put a