vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I would appreciate any help in writing a query to do the following: I have the following tables table 1 -with fields id INT(9) x CHAR(30) y CHAR(100) primary key is 'id' table 2 - with fields userid INT(9) id INT(9) // same as the id in table 1 text CHAR(200) primary key is 'userid, id' table 3 - with fields userid INT(9) username CHAR(30) password CHAR(100) and for example, table 1 has the following entries id x y 1 AAA aaa 2 BBB bbb 3 CCC ccc 4 DDD ddd and table 2 has the following entries id userid text 1 1 TEXT1 4 1 TEXT4 1 100 TEXT100_1 and table 3 has the following entries id username password 1 user1 pass1 2 user2 pass2 3 user3 pass3 ..... 100 user100 pass100 Now, I need a query to generate the following results for 'userid = 1' id x y text 1 AAA aaa TEXT1 2 BBB bbb <null> 3 CCC ccc <null> 4 DDD ddd TEXT4 following results for 'userid = 2' id x y text 1 AAA aaa <null> 2 BBB bbb <null> 3 CCC ccc <null> 4 DDD ddd <null> following results for 'userid=100' id x y text 1 AAA aaa TEXT100_1 2 BBB bbb <null> 3 CCC ccc <null> 4 DDD ddd <null> |
| ||||
| kkmnmaps@gmail.com wrote: > Hi, > > I would appreciate any help in writing a query to do the following: > > I have the following tables > > table 1 -with fields > id INT(9) > x CHAR(30) > y CHAR(100) > primary key is 'id' > > table 2 - with fields > userid INT(9) > id INT(9) // same as the id in table 1 > text CHAR(200) > primary key is 'userid, id' > > table 3 - with fields > userid INT(9) > username CHAR(30) > password CHAR(100) > > and for example, > > table 1 has the following entries > > id x y > 1 AAA aaa > 2 BBB bbb > 3 CCC ccc > 4 DDD ddd > > > and table 2 has the following entries > > id userid text > 1 1 TEXT1 > 4 1 TEXT4 > 1 100 TEXT100_1 > > and table 3 has the following entries > > id username password > 1 user1 pass1 > 2 user2 pass2 > 3 user3 pass3 > .... > 100 user100 pass100 > > Now, I need a query to generate the following results for 'userid = 1' > > id x y text > 1 AAA aaa TEXT1 > 2 BBB bbb <null> > 3 CCC ccc <null> > 4 DDD ddd TEXT4 > > > following results for 'userid = 2' > > id x y text > 1 AAA aaa <null> > 2 BBB bbb <null> > 3 CCC ccc <null> > 4 DDD ddd <null> > > > following results for 'userid=100' > > id x y text > 1 AAA aaa TEXT100_1 > 2 BBB bbb <null> > 3 CCC ccc <null> > 4 DDD ddd <null> so what have you tried? look at left/right outer join syntax. M. |
| Thread Tools | |
| Display Modes | |
|
|