Solved

SQL Select Statement

Posted on 2011-02-25
1
397 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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