Solved

SQL Select Statement

Posted on 2011-02-25
1
402 Views
Last Modified: 2012-06-27
I am attempting to create a select statement that will pair data with the correct record.  I have an ACCIDENT Table which contains the Accident Reports.  I then have a MASTER Table that holds the units involved in the accident.  The third table is the VEHICLE table which will hold all of the codes related to the Unit Number that was in the ACCIDENT.  

The Key in the ACCIDENT table is the report number - OCA_T

The Master Table is using SELECT * FROM MASTER  WHERE OCA_T = ?CURRENTOCA and relation == "DRIVER"   -  (This is working fine)  In the Master Table the there is a field labeled NO which contains the Unit Number.

In my VEHICLE table, I have OCA_T and NO fields.  I want to have it pair up with the MASTER table if the OCA_T+NO == the Master.OCA_T+MASTER.NO.

I am using the following and it does not work....  SELECT * FROM VEHICLE where OCA_T = ?CURRENTOCA .AND. NO = MASTER.NO order by accident  (the accident order is a simple OCA_T+NO)

Any help is greatly appreciated!!

I am using the Select statement as it works with my my Visual Fox Tables as well as SQL.
0
Comment
Question by:goautl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 34984280
Your command
SELECT * FROM VEHICLE where OCA_T = ?CURRENTOCA .AND. NO = MASTER.NO
will select VEHICLE records for one MASTER.NO value (the one which is in the current record).

If you need to retrieve data from two or more tables in one query then you have to include all these tables in the SELECT command and define the joining condition. The simplest command would look like this one:

SELECT * FROM VEHICLE, MASTER ;   && list of output columns (* means all columns) and input tables
where VEHICLE.OCA_T = MASTER.OCA_T ;  && first part of joining condition
  AND VEHICLE.NO = MASTER.NO ;   && second part of joining condition
  AND VEHICLE.OCA_T = ?CURRENTOCA  && filter condition

or same command:

SELECT * FROM VEHICLE ;
INNER JOIN MASTER ON VEHICLE.OCA_T = MASTER.OCA_T  AND VEHICLE.NO = MASTER.NO ;
where VEHICLE.OCA_T = ?CURRENTOCA

But this explanation probably does not help to understand the queries, so I would recommend some SQL course or tutorial, e.g. http://www.w3schools.com/sql/default.asp or  http://www.sqlcourse.com/index.html
0

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question