Solved

SQL Select Statement

Posted on 2011-02-25
1
382 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
1 Comment
 
LVL 41

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now