I'm trying to do the below join, i have two tables as below. What i need is to get a list of all members from the 'members' table that have active set to 1 excluding any members in the admin_privilege s table??
members:
id(PK),uname,ac tive
admin_privilege s:
id(PK),uid(FK-members.id) - SELECT members.id,members.uname,admin_pivileges.uid FROM members, admin_privileges WHERE members.active='1' AND members.id != admin_pivileges.uid
3 1652
There was one or two typo's with the previous query, this on is the one I'm using. - SELECT members.id,members.uname,admin_privileges.uid FROM members, admin_privileges WHERE admin_privileges.uid != members.id AND active = '1'
Atli 5,058
Recognized Expert Expert
Hi.
Joining tables using a comma, like you do, is rarely the best way to join tables. It simply joins all rows in table A with all rows in table B, usually creating a lot more rows then are wanted or needed.
This is why your query fails, because you do not account for all the rows the condition-free join is creating, and assume the tables will only be joined on the PK-FK columns.
You should choose a more appropriate JOIN type when joining tables, and use the ON clause to condition the merger of the tables.
Check out 12.2.8.1. JOIN Syntax in the manual for full details on that.
In your case, however, a JOIN may not be your best option.
A simple sub-query might be more appropriate here.
For example: -
SELECT `id`
-
FROM `members`
-
WHERE `active` = 1
-
AND ( SELECT TRUE
-
FROM `admin_privileges` WHERE `uid` = m.`id`
-
) IS NULL;
Thanks for the help with that, i got a sub query to work for me!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: B. Fongo |
last post by:
I learned MySQL last year without putting it into action; that is why
I face trouble in formulating my queries. Were it a test, then you
would have passed it, because your queries did help me solve my problem.
I'll turn to MySQL doc after getting through this pressing project.
Thanks a lot Roger!
Babale
-----Urspr=FCngliche Nachricht-----
|
by: Bruce Duncan |
last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the
problem...getting the syntax confused) and I'm having a join problem...can
anyone offer some help? Here's my problem:
I have table1 that needs to "left" join to table1A, table1B, and table1C
which is corrently done with the following:
select table1.x, table1a.y, table1b.z, table1c.q
from table1
left join table1a on table1.ID = table1a.ID
left join table1b on table1.ID =...
|
by: Greg |
last post by:
I'm a quantitative securities analyst working with Compustat data
(company fiscal reports and pricing feeds).
My coworker came across a problem that we fixed, but I'd like to
understand 'why' it was happening and just don't get it yet.
Here's the starting query (reduced to simple prefixes):
----INITIAL-----
|
by: Anthony Robinson |
last post by:
I was actually just wondering if someone could possibly take a look
and tell me what I may be doing wrong in this query? I keep getting
ambiguous column errors and have no idea why...?
Thanks in advance!!!
SELECT AIM.AIMRETRIEVAL.AIMRETRIEVALID,
AIM.AIMRETRIEVAL.DESCRIPTION,
AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID,
AIM.ARCHIVERETRIEVAL.STATUSID,
|
by: Phil Powell |
last post by:
<cfquery name="getAll" datasource="#request.dsn#">
SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn,
U.choiceId, U.experience, T.label AS teamLabel, R.label AS
roleLabel
FROM User U LEFT JOIN UserTeamAssoc UTA
ON UTA.userID = U.userID,
Role R, UserRoleAssoc URA, Team T
WHERE U.userID = URA.userID
AND URA.roleID = R.roleID
AND U.userId > 1
| |
by: jason.evans |
last post by:
Hi there.
I am having an intrigueing problem.
I have a query which left joins another query to itself twice. The
original query is derived from a linked table in SQLServer 2000.
When I run it on my pc It runs fine. However for other users in the
office, it behaves as an inner join. ie it only returns the records fo
which the join fields equal each other. This happens on every other pc
|
by: Steve |
last post by:
One of our clients recently upgraded their Office version to 2003. When
they tried to run our program (written in Access 2000), they ended up
with the wrong data. My coworker and I have tested this problem and
found that it ONLY occurs on Windows XP machines running Office 2003.
The problem ends up being that ONE 1-to-1 join in ONE query within the
application does not perform as a 1-to-1 join. It acts as though there
is no join at all....
|
by: MP |
last post by:
Hi
trying to begin to learn database using vb6, ado/adox, mdb format, sql
(not using access...just mdb format via ado)
i need to group the values of multiple fields
- get their possible variations(combination of fields),
- then act on each group in some way ...eg ProcessRs (oRs as RecordSet)...
the following query will get me the distinct groups
|
by: Dave |
last post by:
Guys I am really stuck on this one. Any help or suggestions would be
appreciated.
We have a large table which seemed to just hit some kind of threshold.
They query is somewhat responsive when there are NO indexes on the
table. However, when we index email the query takes forever.
FACTS
- The problem is very "data specific". I can not recreate the
|
by: Anila |
last post by:
Hi Friends,
My problem with Inner join is ...
first i joined two tables and i got the result.
after that iam trying to join one more table its giving syn tax error in JOIN condition.
Here is the Query
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |