| Author |
Topic |
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2009-02-03 : 03:16:43
|
| i have to fetch Upline_ID. select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id=50010001 and placement='L'suppose result: aid isid 2 1 now query is:select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id=2 then Result: aid isid 4 2 5 2now query is:select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id=4 and select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id=5 is there any way to fetch data by a single query Database is: My SQL Ved Prakash Jha |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-03 : 03:23:24
|
| select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id=4 union select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id=5or select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id in (4,5) |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-02-03 : 03:25:07
|
| with cte(aid,isid)as(select upline_id as aid ,advisor_id as isid ,1 as level from members where advisor_id=50010001 and placement='L'union allselect upline_id as aid ,advisor_id as isid ,1 as level from members minner join cte on (m.upline_id=cte.isid))select * from cteJai Krishna |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2009-02-03 : 03:33:15
|
| advisor_id=4 /5 How to assign it first query is:select upline_id as aid ,advisor_id as isid ,1 as level from memberswhere advisor_id=50010001 and placement='L'i know only first value as advisor_id=50010001output:aid isid2 1now query is:select upline_id as aid ,advisor_id as isid ,1 as level from memberswhere advisor_id= 2 //(How to know there is 2 may be result will 3 or any thing) after that query will return 2 recordsand then i have to run query for all records...Ved Prakash Jha |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2009-02-03 : 03:35:17
|
| with CTE (Common Table Expressions) does not support in My sql Databasesit supports in SQL 2005-08Ved Prakash Jha |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2009-02-03 : 04:05:53
|
quote: Originally posted by vedjha with CTE (Common Table Expressions) does not support in My sql Databasesit supports in SQL 2005-08Ved Prakash Jha
then maybe you should post on a MySQL forum instead of a SQL Server one?Em |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-02-03 : 06:21:20
|
Try this:select m3.upline_id as aid ,m3.advisor_id as isid ,1 as level from members m1join members m2 on m2.advisor_id = m1.advisor_idjoin members m3 on m3.advisor_id = m2.advisor_idwhere m1. advisor_id = 50010001 and m1.placement = 'L' Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2009-02-03 : 06:47:06
|
| Thnks :I have runed the query3=500100034=50010004output:aid isid level3 1 13 1 14 1 14 1 1but i expect output as:aid isid level3 1 14 1 15 3 26 3 27 4 28 4 29 5 310 6 311 10 412 11 5 Ved Prakash Jha |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-02-03 : 07:17:52
|
Then please give us sample data... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
vedjha
Posting Yak Master
228 Posts |
Posted - 2009-02-03 : 07:38:14
|
| aid isid level3 1 14 1 15 3 26 3 27 4 28 4 29 5 310 6 311 10 412 11 5it is sampleVed Prakash Jha |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-03 : 08:48:28
|
| where will you get set of values you want to retrieve from? |
 |
|
|
|