Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
span
Starting Member
2 Posts |
Posted - 2011-01-14 : 14:55:34
|
| Hello,I have two tables:1) table containing some ranked data with primary key entryid2) table containing entries of the form (userid, entryid)I want to return the best 30 entries from the 1st table that are not in the 2nd.For example, usually I select rows 1,2,3,4,5 but my user tells me that they don't want to see row 2. Then upon loading the page again, they should see 1,3,4,5,6.How exactly can I set up a query that does that? My ranking query is something likeSELECT * FROM ENTRYTABLE WHERE foo, ORDER BY `bar` desc limit 30How can I modify this query to avoid entries in the second table?Thanks so much. |
|
|
mzuma
Starting Member
2 Posts |
Posted - 2011-01-14 : 16:31:22
|
| You can use NOT IN or MINUSSELECT * FROM Table 1 WHERE [some expressions] AND entryid NOT IN (SELECT entryid FROM table2) ORDER BY `bar` desc limit 30check out the following link:SQL INSQL MINUS |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-01-14 : 16:37:58
|
| You can also do an OUTER JOIN or use a NOT EXISTS clause. |
 |
|
|
span
Starting Member
2 Posts |
Posted - 2011-01-14 : 16:53:19
|
| Perfect - exactly what I needed. Thanks! |
 |
|
|
|
|
|
|
|