need help on sql

need help on sql

Post by Junkon » Sat, 22 Mar 2008 10:02:22


i have 3 tables which are linked to 1 another using foreigh key-
Trades, executions, rawdatas with id as primary key
Trades can have 1 or more executions
Executions must have only 1 rawdatas

The structure is
Rawdatas cols
1. id
2. Date
3. col2
4. col3

Executions.
1. id
2. EntryOrExit
3. col2
4. col3

Trades
1. id
2. col1
3. col2
4. col3



I want to build a query which returns all the trades and return the
value of RawDatas.date where Executions.EntryorExit="Entry"
i need some help.

seede
 
 
 

need help on sql

Post by Peter H. C » Sat, 22 Mar 2008 10:43:43


Fail. Not enough information about the foreign keys; that is, any.

Other than that, I'd have accused you of asking a homework question.
Usually teachers make better questions.

--
67. No matter how many shorts we have in the system, my guards will be
instructed to treat every surveillance camera malfunction as a
full-scale emergency.
--Peter Anspach's list of things to do as an Evil Overlord

 
 
 

need help on sql

Post by Michael Au » Sat, 22 Mar 2008 11:04:17


Please post what you have tried. We can help, but would like to see
where you are going wrong.. and if this is homework you should be
figuring this out for yourself and not having others do it for you...(I
doubt any real trading company would hire someone to do this in MySQL -
especially someone who shows very little knowledge of SQL for something
this simple...)
 
 
 

need help on sql

Post by Junkon » Sat, 22 Mar 2008 19:50:25

On Mar 20, 10:04m, Michael Austin < XXXX@XXXXX.COM >



select r.created_at,t.* from trades t, executions e, rawdatas r where
r.execution_id=e.id and e.trade_id=t.id
and e.entryorexit='ENTRY'

The # of rows in Trades=353. The rows returned by this sql is 409
because there are 1:n relationshiop between Trades and Executions. I
just wanted the values form the first record from executions that is
related to Trades. I would really appreciate some help here because i
can go only so far.
PS: This is not homework. I am a starter programmer doing some work
for a smalltime company.
 
 
 

need help on sql

Post by Paul Lautm » Sat, 22 Mar 2008 20:34:58


The answer is here:
http://www.yqcomputer.com/
you want to base your query on the third example, the one with the LEFT
JOIN.
 
 
 

need help on sql

Post by Junkon » Sun, 23 Mar 2008 02:14:05

On Mar 21, 7:34m, "Paul Lautman" < XXXX@XXXXX.COM >





thanks. it works for me
 
 
 

need help on sql

Post by Michael Au » Sun, 23 Mar 2008 02:49:33


Good luck. Only advice I can give is for you to spend every waking hour
for the next few weeks reading, researching and testing - get yourself a
Linux box at home - Fedora or most any of the downloadable Linux
distro's come with MySQL included and research research then test test
and test some more...
 
 
 

need help on sql

Post by ThanksButN » Sun, 23 Mar 2008 04:37:19


Ah, the Monty Python Flight School, huh?

Good luck!!