| Author |
Topic |
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-05-26 : 11:06:19
|
| Hello Everyone,why cant I use this:select * from tblusers as bwhere b.idUser IN (select a.idUser from tblnaw as a)AND b.idUser IN (select c.idUser from tblijsbrekeres as c)Result:select a.idUser from tblnaw as ais 1, 2, 3Result:select * from tblusers as bis 1, 2, 3, 4, 5, 6So the result I want is 1, 2, 3thanxxBjorn |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2004-05-26 : 11:41:08
|
| whats the count from tblijsbrekeres??? |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-05-26 : 11:47:59
|
Sorry mist one tabel.tblijsbrekers is 1, 2, 3, 6, 7, 8ThanxxBjorn |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2004-05-26 : 11:56:22
|
So what exactly is the problem???Seems fine to me..create table #tblnaw (idUser int)create table #tblusers(idUser int)create table #tblijsbrekeres(idUser int)insert into #tblnawselect 1 union select 2 union select 3insert into #tblusersselect 1 union select 2 union select 3 union select 4 union select 5 union select 6insert into #tblijsbrekeres select 1 union select 2 union select 3 union select 6 union select 7 union select 8select * from #tblusers as bwhere b.idUser IN (select a.idUser from #tblnaw as a)AND b.idUser IN (select c.idUser from #tblijsbrekeres as c) |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-05-26 : 12:31:07
|
| ## Table structure for table 'ijsbrekers'#CREATE TABLE IF NOT EXISTS ijsbrekers ( userId smallint(3) unsigned NOT NULL auto_increment, PRIMARY KEY (userId));## Dumping data for table 'ijsbrekers'#INSERT INTO ijsbrekers VALUES("3");INSERT INTO ijsbrekers VALUES("4");INSERT INTO ijsbrekers VALUES("5");INSERT INTO ijsbrekers VALUES("6");## Table structure for table 'naw'#CREATE TABLE IF NOT EXISTS naw ( userId smallint(3) unsigned NOT NULL auto_increment, PRIMARY KEY (userId));## Dumping data for table 'naw'#INSERT INTO naw VALUES("1");INSERT INTO naw VALUES("2");INSERT INTO naw VALUES("3");## Table structure for table 'users'#CREATE TABLE IF NOT EXISTS users ( userId smallint(3) unsigned NOT NULL auto_increment, PRIMARY KEY (userId));## Dumping data for table 'users'#INSERT INTO users VALUES("1");INSERT INTO users VALUES("2");INSERT INTO users VALUES("3");INSERT INTO users VALUES("4");INSERT INTO users VALUES("5");INSERT INTO users VALUES("6");INSERT INTO users VALUES("7");INSERT INTO users VALUES("8");INSERT INTO users VALUES("9");INSERT INTO users VALUES("10");select * from users as bwhere b.userId IN (select a.userId from naw as a)AND b.userId IN (select c.userId from ijsbrekers as c)This does not work. But all single query's work!Hope you can help me out.ThanxxBjorn |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2004-05-26 : 13:15:27
|
| What database are you using btw as this isn't SQL Server DDL?!?!? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-05-26 : 13:17:44
|
| What database is this? mySQL?I always thought of this kind of like my SQLTeam...Never mySQLTeam though...Is it mySQL?Brett8-) |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-05-26 : 13:25:59
|
I get 3...which is what you're suppose to getUSE NorthwindGOCREATE TABLE ijsbrekers (userId int PRIMARY KEY)GOINSERT INTO ijsbrekers(UserID)SELECT 3 UNION ALLSELECT 4 UNION ALLSELECT 5 UNION ALLSELECT 6GOCREATE TABLE naw (userId int PRIMARY KEY)GOINSERT INTO naw(UserID)SELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 3GOCREATE TABLE myUsers99 (userId int PRIMARY KEY)GOINSERT INTO myUsers99(UserID)SELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 3 UNION ALLSELECT 4 UNION ALLSELECT 5 UNION ALLSELECT 6 UNION ALLSELECT 7 UNION ALLSELECT 8 UNION ALLSELECT 9 UNION ALLSELECT 10GOSELECT * FROM myUsers99 WHERE userId IN (SELECT userId FROM naw) AND userId IN (SELECT userId FROM ijsbrekers)GODROP TABLE ijsbrekersDROP TABLE nawDROP TABLE myUsers99GO Brett8-)EDIT: Maybe you could check out http://www.mySQLTeam.com? |
 |
|
|
neutcomp
Posting Yak Master
111 Posts |
Posted - 2004-05-26 : 14:45:11
|
| Yes it is MySQL, not everybody can offord(earn) a SQLserver.I wish there was a http://www.mySQLTeam.comSo nobody can help me with this one? Thats a shame.Thanx anywayBjorn :-( |
 |
|
|
|