|
Hi friends,
I have a table like below,
account_no linked_acc_no
--------- -------------
aaa bbb
bbb ccc
bbb ddd
eee ccc
ddd fff
fff ggg
eee hhh
hhh iii
xxx zzz
xxx yyy
vvv www
I need a query to select account no which are linked with 'aaa'.
So the o/p should be like this,
o/p
---
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
any one can help me on this?..
|
|
|
|
|
Hi friends,
I got a solutions.
Thanks.
|
|
|
|
|
|
There may be better solutions. They are not likely to be shared if you decide to keep yours to yourself.
|
|
|
|
|
I wonder what precipatated the solution.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Just had a flash back from Chemistry 110 - 35 years ago!
|
|
|
|
|
T.Senthilnathan wrote: I got a solutions.
Glad you got that. BTW why don't you post that solution in your message....Also are you sure your solution is best?
|
|
|
|
|
hello
i need help i am working on database and i have connected it to the c# i need small thing i have created a serach button but i dont want to show the result on data grid view if u can help plz give me the answer and the code
ty
|
|
|
|
|
Cross posting[^] in the C# forum won't help much.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
|
Hi all
I want to count records in a table respect to each date.
select count(id), add_date from packages group by add_date
this gives results only for dates which has exist.
Say I want to find the count in a range of dates, and if records not found then the count as zero.
Is it possible to do this with MySQL
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi,
Perhaps the easiest way could be that you create a new table, for example SingleDate and add all necessary dates to that table. After that, using outer join, join the data between the date table and your table. So something like:
SELECT ...
FROM SingleDate d LEFT OUTER JOIN Packages p
ON d.Date = p.Add_Date
GROUP BY d.Date
|
|
|
|
|
Thanks for the comment.
Should I do with a temporary table or create a table in the database permanently? I've tried the following.
CREATE TEMPORARY TABLE date_col (add_dates nvarchar(50));
INSERT INTO date_col (add_dates) VALUES('2011-04-06');
SELECT * FROM date_col;
But stuck with two things.
1. How can I loop the date range and add all the dates into the table
2. I think to be in safe side I want to drop the table after the query required data, isn't it?
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I would do it permanently since most likely this is not the only case when you need the dates.
To fill the table. Why not create a stored procedure. If you need to fill for a specific period again then you can use the same procedure. Something like:
CREATE PROCEDURE DateFill(d1 DATE, d2 DATE)
BEGIN
SET @d3 = d1;
REPEAT
INSERT INTO DateTable (date_co) VALUES (@d3);
SET @d3 = DATE_ADD(@d3, INTERVAL 1 DAY);
UNTIL @d3 > d2
END;
For dropping the table, I wouldn't since if the table is created and permanent you can continue to use it later. Just add a long enough date range to the table (say, 500 years )
Also it might be a good idea to add an index to the table to speed up the usage: http://dev.mysql.com/doc/refman/5.1/en/create-index.html[^]
|
|
|
|
|
Actually I don't want to keep records for a long time. Only for an instance.
The requirement is, for few sales rep I want to find the sales in a date range. That is for each sales rep I want to find the sales in a date range.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: The requirement is, for few sales rep I want to find the sales in a date range
This is a different thing. What I'm saying is that consider populating the table with long enough date range. And when you use the table take only the relevant portion of dates from it using proper WHERE condition. For example:
SELECT ...
FROM DateTable dt LEFT OUTER JOIN MyTable mt
ON dt.DateColumn = mt.DateColumn
WHERE dt.DateColumn BETWEEN @startdate AND @enddate
This way you can reuse the same data every time you fetch data for a new date range without having to re-create the dates.
|
|
|
|
|
Oh, I think I got your point now.
What you are saying is keep dates in a permanent table ( for a long dates, eg: 2000-01-01 to 2500-01-01) and use that table to join with the other table in the date range I want to.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Exactly
|
|
|
|
|
Thanks buddy.
I'll give a try and let you know.
So I'll keep this thread as it is.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Step 1: Create a table variable with a date column and fill the table with the date range that you need (probably the min and max dates from 'packages' table)
Step 2: Use your query and do a union with the temp table created in step 1
|
|
|
|
|
Shameel wrote: Step 1: Create a table variable with a date column and fill the table with the date range that you need (probably the min and max dates from 'packages' table)
So I can move with a temporary table or a permanent one. But I'm stuck with how to insert range of dates into it. Something like this ...
CREATE TEMPORARY TABLE date_col (add_dates nvarchar(50));
INSERT INTO date_col (add_dates) VALUES ('2011-04-06' through '2011-04-01');
I appreciate your help all the time...
CodingLover
|
|
|
|
|
|
|
Hi all,
My web application base on money transactions. My client wants to keep a realtime backups. That means i host the web app in one server and have another server for backups. If system down in the hosted server there is a backup link to the system in backup server. The problem is i want to update the backup server database in the same time when updating the original server database. What is the best and more efficient solution for this requirement.
thanks
|
|
|
|
|