Home » Performance » MySQL » Display query result from two tables...
Display query result from two tables... [message #941] Fri, 16 March 2007 16:16 Go to next message
aljosa.motore  is currently offline aljosa.motore
Messages: 1
Registered: March 2007
Junior Member
I have two tables:
Table A:
Code | Name
100 | Name A
200 | Name B
300 | Name C

Table B:
Code | Date | Qty | Value
100 | 2007-01-01 | 10 | 123
100 | 2007-02-01 | -2 | 300
200 | 2007-02-01 | 3 | 100

What I want is to get this result:
Result Table on date example 2007-01-05:
Code | Name | Qty | Value
100 | Name A | 10 | 123

Result Table on date example 2007-02-05:
Code | Name | Qty | Value
100 | Name A | 8 | 300
200 | Name B | 3 | 100

And so on....

So, Table 1 is primary and Table B is some sort of history what happened with some "Code" on some dates.... What I want is to get result on certain date with right QTY on that date and also right Value on that date (or most nearest value).

Tahnks...
Re: Display query result from two tables... [message #970 is a reply to message #941 ] Thu, 22 March 2007 09:50 Go to previous message
tanj  is currently offline tanj
Messages: 16
Registered: March 2007
Location: France
Junior Member
aljosa.motore wrote on Fri, 16 March 2007 21:16

I have two tables:
Table A:
Code | Name
100 | Name A
200 | Name B
300 | Name C

Table B:
Code | Date | Qty | Value
100 | 2007-01-01 | 10 | 123
100 | 2007-02-01 | -2 | 300
200 | 2007-02-01 | 3 | 100

What I want is to get this result:
Result Table on date example 2007-01-05:
Code | Name | Qty | Value
100 | Name A | 10 | 123

Result Table on date example 2007-02-05:
Code | Name | Qty | Value
100 | Name A | 8 | 300
200 | Name B | 3 | 100

And so on....

So, Table 1 is primary and Table B is some sort of history what happened with some "Code" on some dates.... What I want is to get result on certain date with right QTY on that date and also right Value on that date (or most nearest value).

Tahnks...


Use a JOIN condition, like

SELECT code, name, qty, value FROM b INNER JOIN a USING (code) WHERE date = '2007-02-05';

HF :=)
Previous Topic:How to trace mysql server
Next Topic:New, Need Help
Goto Forum:
  


Current Time: Fri Jul 10 01:23:40 EDT 2009

Total time taken to generate the page: 0.01025 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.