vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| On Thu, 20 Mar 2008 18:02:22 -0700 (PDT), Junkone wrote: > 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. 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 |
| |||
| Junkone wrote: > 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 > > > 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...) |
| |||
| On Mar 20, 10:04*pm, Michael Austin <maus...@firstdbasource.com> wrote: > Junkone wrote: > > 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 > > 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...)- Hide quoted text - > > - Show quoted text - 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. |
| |||
| Junkone wrote: > On Mar 20, 10:04 pm, Michael Austin <maus...@firstdbasource.com> > wrote: >> Junkone wrote: >> > 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 >> >> 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...)- Hide quoted text - >> >> - Show quoted text - > > 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. The answer is here: http://dev.mysql.com/doc/refman/5.0/...group-row.html you want to base your query on the third example, the one with the LEFT JOIN. |
| |||
| On Mar 21, 7:34*am, "Paul Lautman" <paul.laut...@btinternet.com> wrote: > Junkone wrote: > > On Mar 20, 10:04 pm, Michael Austin <maus...@firstdbasource.com> > > wrote: > >> Junkone wrote: > >> > 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 > > >> 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...)- Hide quoted text - > > >> - Show quoted text - > > > 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. > > The answer is here:http://dev.mysql.com/doc/refman/5.0/...column-group-r... > you want to base your query on the third example, the one with the LEFT > JOIN.- Hide quoted text - > > - Show quoted text - thanks. it works for me |
| |||
| Junkone wrote: > On Mar 20, 10:04 pm, Michael Austin <maus...@firstdbasource.com> > wrote: >> Junkone wrote: >>> 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 >> 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...)- Hide quoted text - >> >> - Show quoted text - > > 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. 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... |