This is a simple join but I am having trouble with it. I feel like such
an idiot.
I start with this select statement, which works fine:
$query =
"SELECT a.auction, a.winner, b.id
FROM PHPAUCTIONXL_wi nners a, PHPAUCTIONXL_au ctions b
WHERE a.auction=b.id" ;
Now I only want the results from auctions with ids that are not listed
in the 'archived' field of the PHPAUCTIONXL_ar chived table. So I added
another table and an AND to the SELECT statement. Now I don't understand
why it doesn't show the auctions which are not archived.
$query =
"SELECT a.auction, a.winner, b.id
FROM PHPAUCTIONXL_wi nners a, PHPAUCTIONXL_au ctions b,
PHPAUCTIONXL_ar chived c
WHERE a.auction=b.id
AND a.auction !=c.archived";
How do I get this to work ?
red 8 2055
I noticed that Message-ID: <a4************ **********@twis ter.nyc.rr.com>
from red contained the following: AND a.auction !=c.archived";
How do I get this to work ?
Just a guess (I'm not a major SQL guru)
AND NOT a.auction =c.archived
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
red wrote: This is a simple join but I am having trouble with it. I feel like such an idiot.
I start with this select statement, which works fine: $query = "SELECT a.auction, a.winner, b.id FROM PHPAUCTIONXL_wi nners a, PHPAUCTIONXL_au ctions b WHERE a.auction=b.id" ;
Now I only want the results from auctions with ids that are not listed in the 'archived' field of the PHPAUCTIONXL_ar chived table. So I added another table and an AND to the SELECT statement. Now I don't understand why it doesn't show the auctions which are not archived.
$query = "SELECT a.auction, a.winner, b.id FROM PHPAUCTIONXL_wi nners a, PHPAUCTIONXL_au ctions b, PHPAUCTIONXL_ar chived c WHERE a.auction=b.id AND a.auction !=c.archived";
How do I get this to work ?
red http://www.w3schools.com/sql
Try it. Good site for starters. Really.
good luck!
Regards
Stijn Verholen wrote: Geoff Berrow wrote:
I noticed that Message-ID: <a4************ **********@twis ter.nyc.rr.com> from red contained the following:
AND a.auction !=c.archived";
How do I get this to work ? Just a guess (I'm not a major SQL guru)
AND NOT a.auction =c.archived
or: AND a.auction <> c.archived
http://dev.mysql.com/doc/mysql/en/co...operators.html http://dev.mysql.com/doc/mysql/en/lo...operators.html
HTH
ND NOT a.auction =c.archivedT results in no rows
AND a.auction <> c.archived results in all rows
so niether one filters out the archived auctions
"red" <gr*****@reenie .org> wrote $query = "SELECT a.auction, a.winner, b.id FROM PHPAUCTIONXL_wi nners a, PHPAUCTIONXL_au ctions b, PHPAUCTIONXL_ar chived c WHERE a.auction=b.id AND a.auction !=c.archived";
How do I get this to work ?
I think there's a couple of ways to do this:
select a.auction, a.winner, b.id
from (PHPAUCTIONXL_w inners a join PHPAUCTIONXL_au ctions b on a.auction=b.id)
where not exists (select archived from PHPAUCTIONXL_ar chived c where
c.archived = a.auction)
or
select a.auction, a.winner, b.id, c.archived
from (PHPAUCTIONXL_w inners a join PHPAUCTIONXL_au ctions b on a.auction=b.id)
left join PHPAUCTIONXL_ar chived c on a.auction=c.arc hived
where c.archived is null
Think of it as a multi step process:
You need to do an inner join on a & b first,
then each row is checked against the archived table and rejected if there's
a match.
My sql is a bit rusty, and this page refreshed my memory about exists... http://mysqld.active-venture.com/EXI...ubqueries.html
-- Dan
Dan Stumpus wrote: "red" <gr*****@reenie .org> wrote
$query = "SELECT a.auction, a.winner, b.id FROM PHPAUCTIONXL_wi nners a, PHPAUCTIONXL_au ctions b, PHPAUCTIONXL_ archived c WHERE a.auction=b.id AND a.auction !=c.archived";
How do I get this to work ?
I think there's a couple of ways to do this:
select a.auction, a.winner, b.id from (PHPAUCTIONXL_w inners a join PHPAUCTIONXL_au ctions b on
a.auction=b.id) where not exists (select archived from PHPAUCTIONXL_ar chived c where c.archived = a.auction)
This is the result I got:
Error
SQL-query :
SELECT a.auction, a.winner, b.id
FROM (
PHPAUCTIONXL_wi nners a
JOIN PHPAUCTIONXL_au ctions b ON a.auction = b.id
)
WHERE NOT
EXISTS (
SELECT archived
FROM PHPAUCTIONXL_ar chived c
WHERE c.archived = a.auction
)
MySQL said:
You have an error in your SQL syntax near 'ON a.auction = b.id ) WHERE
NOT EXISTS ( SELECT archived FROM PHPAUCTIONXL_ar ' at line 1 or
select a.auction, a.winner, b.id, c.archived from (PHPAUCTIONXL_w inners a join PHPAUCTIONXL_au ctions b on
a.auction=b.id) left join PHPAUCTIONXL_ar chived c on a.auction=c.arc hived where c.archived is null
This is the result I got:
Error
SQL-query :
SELECT a.auction, a.winner, b.id, c.archived
FROM (
PHPAUCTIONXL_wi nners a
JOIN PHPAUCTIONXL_au ctions b ON a.auction = b.id
)
LEFT JOIN PHPAUCTIONXL_ar chived c ON a.auction = c.archived
WHERE c.archived IS NULL
LIMIT 0 , 30
MySQL said:
You have an error in your SQL syntax near 'ON a.auction = b.id ) LEFT
JOIN PHPAUCTIONXL_ar chived c ON a.auction = c.archiv' at line 1
Think of it as a multi step process:
You need to do an inner join on a & b first, then each row is checked against the archived table and rejected if
there's a match.
My sql is a bit rusty, and this page refreshed my memory about exists...
http://mysqld.active-venture.com/EXI...ubqueries.html
-- Dan
Ed:
I just created the tables and fields on my xp box (mysql 4.1) and ran the
queries.
Results are below...(I shortened the tablenames by removing the PHPAUCTIONXL
prefix):
"Ed Simmons" <hu*@huh.com> wrote SELECT a.auction, a.winner, b.id FROM ( PHPAUCTIONXL_wi nners a JOIN PHPAUCTIONXL_au ctions b ON a.auction = b.id ) WHERE NOT EXISTS (
SELECT archived FROM PHPAUCTIONXL_ar chived c WHERE c.archived = a.auction )
MySQL said:
You have an error in your SQL syntax near 'ON a.auction = b.id ) WHERE NOT EXISTS ( SELECT archived FROM PHPAUCTIONXL_ar ' at line 1
== cut and paste from my query analyzer follows ==
SELECT a.auction, a.winner, b.id
FROM (
winners a
JOIN
auctions b ON a.auction = b.id
) where not exists (select archived from archived c
where c.archived=a.au ction)
....and it ran successfully, rejecting the transaction if it was in the
archived table,
and showing it if not archived.
Error SQL-query :
SELECT a.auction, a.winner, b.id, c.archived FROM ( PHPAUCTIONXL_wi nners a JOIN PHPAUCTIONXL_au ctions b ON a.auction = b.id ) LEFT JOIN PHPAUCTIONXL_ar chived c ON a.auction = c.archived WHERE c.archived IS NULL LIMIT 0 , 30
MySQL said:
You have an error in your SQL syntax near 'ON a.auction = b.id ) LEFT JOIN PHPAUCTIONXL_ar chived c ON a.auction = c.archiv' at line 1
I don't know what's wrong, but the below query was cut/pasted from my query
analyzer, and it ran perfectly (also on mysql 4.1):
select a.auction, a.winner, b.id, c.archived
from (winners a join auctions b on
a.auction=b.id)
left join archived c on a.auction=c.arc hived
where c.archived is null
I was relieved that they worked right away (since my original post was just
off the top of my head).
Could you have created the tables or fields with different spellings?
Scratching my head,
-- Dan
Dan Stumpus wrote: Ed:
I just created the tables and fields on my xp box (mysql 4.1) and ran the queries. Results are below...(I shortened the tablenames by removing the PHPAUCTIONXL prefix):
"Ed Simmons" <hu*@huh.com> wrote
SELECT a.auction, a.winner, b.id FROM ( PHPAUCTIONXL_ winners a JOIN PHPAUCTIONXL_au ctions b ON a.auction = b.id ) WHERE NOT EXISTS (
SELECT archived FROM PHPAUCTIONXL_ar chived c WHERE c.archived = a.auction )
MySQL said:
You have an error in your SQL syntax near 'ON a.auction = b.id ) WHERE NOT EXISTS ( SELECT archived FROM PHPAUCTIONXL_ar ' at line 1
== cut and paste from my query analyzer follows ==
SELECT a.auction, a.winner, b.id FROM ( winners a JOIN auctions b ON a.auction = b.id ) where not exists (select archived from archived c where c.archived=a.au ction)
...and it ran successfully, rejecting the transaction if it was in the archived table, and showing it if not archived.
Error SQL-query :
SELECT a.auction, a.winner, b.id, c.archived FROM ( PHPAUCTIONXL_ winners a JOIN PHPAUCTIONXL_au ctions b ON a.auction = b.id ) LEFT JOIN PHPAUCTIONXL_ar chived c ON a.auction = c.archived WHERE c.archived IS NULL LIMIT 0 , 30
MySQL said:
You have an error in your SQL syntax near 'ON a.auction = b.id ) LEFT JOIN PHPAUCTIONXL_ar chived c ON a.auction = c.archiv' at line 1
I don't know what's wrong, but the below query was cut/pasted from my query analyzer, and it ran perfectly (also on mysql 4.1):
select a.auction, a.winner, b.id, c.archived from (winners a join auctions b on a.auction=b.id) left join archived c on a.auction=c.arc hived where c.archived is null
I was relieved that they worked right away (since my original post was just off the top of my head). Could you have created the tables or fields with different spellings?
Scratching my head,
-- Dan
Anyway I don't know what the problem was. I was kinda hopin someone
could understand and explain the error message so they could explain
what it was getting at.
Although I would love to be able to write more complex joins I decided
the whole approach was wrong. Instead of using an archive table with a
list of auctions on the auction table that are archived, I now move all
the values in the archived auctions to thier own table.
I realized that if I archived 2000 auctions a week, at the end of the
year I would have a table with over 100,000 auctions. Not too bad for
the archive because it won't get used as much. But the active auctions,
should be on separate table. This thread has been closed and replies have been disabled. Please start a new discussion. 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: Ike |
last post by:
Oh I have a nasty query which runs incredibly slowly. I am running MySQL
4.0.20-standard. Thus, in trying to expedite the query, I am trying to set
indexes in my tables.
My query requires four inner joins, as follows :
SELECT DISTINCT
upcards.id,statuskey.status,upcards.firstname,upcards.lastname,originkey.ori
gin,associatekey.username,associatekey2.username,upcards.deleted
FROM upcards,status,origins,associates
INNER JOIN status...
|
by: Beachvolleyballer |
last post by:
hi there
anyone had an idea to join following 2 queries to 1????
----- QUERY 1 ---------------------------------------------
SELECT TMS_CaseF_2.Name AS TCDomain_0,
TMS_CaseF_3.Name AS TCDomain_1,
TMS.CaseF.Name AS TCFolder_2,
TMS_CaseF_1.Name AS TCFolder_3,
|
by: Matt |
last post by:
Hello
I have to tables ar and arb, ar holds articles and a swedish
description, arb holds descriptions in other languages.
I want to retreive all articles that match a criteria from ar and also
display their corresponding entries in arb, but if there is NO entry
in arb I still want it to show up as NULL or something, so that I can
get the attention that there IS no language associated with that
article.
| |
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: Ian Boyd |
last post by:
i know nothing about DB2, but i'm sure this must be possible.
i'm trying to get a client to create a view (which it turns out is called a
"Logical" in DB2). The query needs a LEFT OUTER JOIN, but he doesn't know
how to do that, or even if he can, and i don't have to time to learn DB2
from scratch right now.
The following SQL Query is a trimmed sample of the full View (i.e. Logical)
definition - and i would create it on an SQL based...
|
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: 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: Chamnap |
last post by:
Hello, everyone
I have one question about the standard join and inner join, which one
is faster and more reliable? Can you recommend me to use? Please,
explain me...
Thanks
Chamnap
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
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...
| |