473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Query help needed

I have 2 dbs

a)Relation
User | Group
4 | 2
4 | 3
5 | 4
5 | 5
4 | 4

b)Group
ID | Name
2 | Grp1
3 | Grp2
4 | Grp3
5 | Grp4
What i would like to do is get a result set of
Relation.Group, Group.Name
5, Grp4

Info at hand before query is user=4, so what i am looking for is all
groups that are not subscribed by user 4.

So far i tried:
$Query = 'SELECT DISTINCT relation.group, group.Name
FROM `group`, `relation` WHERE relation.user !=
\''.$userid.'\' AND relation.group = group.id';

This just gives me all groups that do not have user=4.

How do i modify it.
Thanks in advance.

Jul 20 '05 #1
2 1482
Nick wrote:
What i would like to do is get a result set of
Relation.Group, Group.Name
5, Grp4


Here's an example that uses subqueries (requires MySQL 4.1 or later):

SELECT DISTINCT G.ID, G.Name
FROM group G INNER JOIN relation R ON G.ID = R.Group
WHERE G.ID NOT IN
(SELECT R2.Group FROM relation R2 WHERE R2.User = $user)

Here's an example using outer joins (works with MySQL 4.0 or 3.2x):

SELECT DISTINCT G.ID, G.Name
FROM group G LEFT OUTER JOIN relation R
ON (G.ID = R.Group AND R.User = $user)
WHERE R.User IS NULL

Caveat: these queries are not tested.

Regards,
Bill K.
Jul 20 '05 #2
Thanks,
That worked great.
On Fri, 24 Sep 2004 16:23:33 -0700, Bill Karwin <bi**@karwin.com>
wrote:
Nick wrote:
What i would like to do is get a result set of
Relation.Group, Group.Name
5, Grp4


Here's an example that uses subqueries (requires MySQL 4.1 or later):

SELECT DISTINCT G.ID, G.Name
FROM group G INNER JOIN relation R ON G.ID = R.Group
WHERE G.ID NOT IN
(SELECT R2.Group FROM relation R2 WHERE R2.User = $user)

Here's an example using outer joins (works with MySQL 4.0 or 3.2x):

SELECT DISTINCT G.ID, G.Name
FROM group G LEFT OUTER JOIN relation R
ON (G.ID = R.Group AND R.User = $user)
WHERE R.User IS NULL

Caveat: these queries are not tested.

Regards,
Bill K.


Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Irlan agous | last post by:
$query = "update reactie,form set 'reactie.persemail' = 'form.email' where 'reactie.persid' = 'form.id' AND reactie.persemail='' "; How can i get this query to work? Irlan
20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
6
by: paii | last post by:
I have a table that stores job milestone dates. The 2 milestones I am interested in are "Ship Date" TypeID 1 and "Revised Ship Date" TypeID 18. All jobs have TypeID 1 only some jobs have TypeID 18....
3
by: Eagle | last post by:
Hi all, This one's drivin' me nuts. Any help would be appreciated. (Access 2000). I have 3 tables: tblTools: having the basic data of a tool and a field (txt) showing yes or no with regard to...
3
by: cover | last post by:
I have a table with 50 fields that receive input depending on whether that input came in from a 'shaker' form or a 'conveyor' form. Input from the 'conveyor' form might populate 25 fields while...
3
by: faceman28208 | last post by:
Over the past few years I have consulted on six large projects that all independently arrived at the same moronic design desision: The use of SQL query classes. No, I don't mean a class...
0
by: Chuck36963 | last post by:
Hi all, I've been working on a listing problem and I can't figure out how to work it out. I have looked far and wide on the web to find answers, but I'd like other peoples input on my project in...
8
by: Roland Hall | last post by:
In Access you use "*" + + "*", + can be replaced with & Calling a parameterized query in Access requires % be used in place of *, however, all that I have read show dynamic SQL passed to Access: ...
2
by: sara | last post by:
I am helping a non-profit track their elder clients and care given to the clients. The organization would like a report that shows various info on ALL clients, such as: # in each town, # and...
20
by: exipnakias | last post by:
Hello Guys. In a form I created a listbox which looks up the values of a table. I want: 1) ..to create a query where a parameter will be needed in order to be loaded. But I do not want to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.