473,387 Members | 1,876 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,387 software developers and data experts.

Help writing SQL statement in PHP script

This might be in the wrong group, but...

Here is an example of my data:

entry_id cat_id
1 20
2 25
3 30
4 25
5 35
6 25
2 30
2 35
3 35

As you can see, entry_id's 2 and 3 both belong to cat_id 30 and 35

I have captured the cat_id's 30 and 35 with my script, so I need all
entry_id's that belong to BOTH cat_id 30 and 35.

I tried "Select entry_id from myTable where cat_id = '30' and cat_id =
'35' but obviously that is incorrect.

Can someone help? Thanks...
Jun 2 '08
118 4509
On May 15, 4:08 am, vkay...@gmail.com wrote:
Amen. Any proposed solution that skips this step is incomplete. One
shouldn't rely on a broken data model and expect to get good results.
I was wrong here. The data model is too vague to know what table
design is being used. Jerry's solution doesn't rely on a broken model
at all.
Jun 27 '08 #101
I was wrong.. Jerry's approach is fine and normalized well.

On May 15, 3:01 am, vkay...@gmail.com wrote:
Jun 27 '08 #102
On May 15, 11:09 pm, oxis...@yahoo.com wrote:

I was wrong in this post.. Jerry's table has a 3-column key, so of
course there can be dups on 2 columns... It is an accurate scenario
that tests the problem.

Ron Doyle [oxision at yahoo.com]
Jun 27 '08 #103
On May 15, 11:24 pm, oxis...@yahoo.com wrote:
On May 15, 10:13 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Mitch Sherman wrote:
Normalizing it first can do no harm and is certainly an improvement. A
relational table doesn't need redundant rows.
And there is nothing to say the table has redundant rows. Again - this
may be the table structure - we don't know:
Jerry is correct. We can't be sure how many columns are there, so my
post was not really relevant.

Ron Doyle [oxision at yahoo.com]

Jun 27 '08 #104
This post I made was rude course a lie.. Jerry is a very smart guy.
His comments in this newsgroup to everyone.

Please disregard my foolish statements.

On May 15, 10:34 pm, oxis...@yahoo.com wrote:
On May 15, 9:49 pm, Mitch Sherman <mitch.sher...@hush.aiwrote:
On Thu, 15 May 2008 11:50:57 -0400, Jerry Stuckle
<jstuck...@attglobal.netwrote:
>Corey Jansen wrote:
>Jerry's approach results in a "cartesian explosion."
>Then you have a broken database server. You need to report that as a
>bug to MySQL ASAP. A lot of people depend self-join queries like this!
Not at all, this is a bug in your query. It produced the same result
here. MySQL did exactly what you told it to do. You seem desperate to
avoid acknowledging this, resorting even to making up fictitious MySQL
bug reports.

Classic Jerry Stuckle. He is known to be a compulsive liar. I'll bet
he's thinking right now:

"Boy I've put my foot in it, but maybe I can still try hard to
convince people who don't know any better that I'm right! Maybe if I
throw a temper tantrum that will magically turn my bad advice into
good advice!"

Jerry is the only one arguing this doomed position. I don't expect his
false pride will let him admit it, so we can expect his trolling to
continue unabated. Fact is, he's still perpetuating awful
misconceptions about sql.

Ron Doyle [oxision at yahoo.com]
Jun 27 '08 #105
My post was a lie and lame. Jerry's an incredibly smart and well-
respected guy and his posts in this newsgroup are extremely useful to
everyone.

Please disregard my cilly posts such as this one.

Ron Doyle [oxision at yahoo.com]

oxis...@yahoo.com wrote:
Ron Doyle [oxision at yahoo.com]
Jun 27 '08 #106
On May 15, 10:51 pm, oxis...@yahoo.com wrote:
>
I was wrong in this previous post... Jerry's query of course works and
he pointed out several times that you use DISTINCT if you want to
unique the results... DIsregard my post.

Ron Doyle [oxision at yahoo.com]
Jun 27 '08 #107
On May 15, 10:51 pm, oxis...@yahoo.com wrote:
On May 15, 9:52 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
No, the critical point YOU'RE MISSING is that the table may be
normalized - AND STILL HAVE DUPLICATES IN THESE COLUMNS.
That is the critical point!

Totally incorrect. I refer you to the Wikipedia definition:

A table is in first normal form (1NF) if and only if it faithfully
represents a relation.[3] Given that database tables embody a relation-
like form, the defining characteristic of one in first normal form is
that it does not allow duplicate rows or nulls.
Well I was wrong and made a mistake and didn't understand Jerry's
post. Of course he meant there were duplicates in 2 columns only, but
not across all columns in the row. Of course his table is normalized
so my post was BS. Please disregard it.

Ron Doyle [oxision at yahoo.com]

Jun 27 '08 #108
On Sat, 17 May 2008 11:12:01 -0500, Jamie Nelson wrote:
>>
Nothing in the description of the problem prohibits such an occurrence.

That can't occur because the first step in the solution is to strip duplicates.
I was wrong, Jerry is correct. The first step is invalid because
duplicates may exist in the table. The problem doesn't prohibit it and so
these rows can't be removed without potentially breaking something.

--
Jamie Nelson

Jun 27 '08 #109
On Sat, 17 May 2008 11:13:54 -0500, Jamie Nelson wrote:
On Tue, 13 May 2008 12:02:59 -0400, Jerry Stuckle wrote:
>>That was addressed in the response, but it looks like you missed it.

You make the mistake of assuming the data is not normalized. I think the
point of Peter's post was to ensure that the data was indeed normalized.

Which, if it is not normalized, will not work.

As I said - there was nothing in the original problem description to
prohibit it. And the correct answer doesn't require unique entries.

The data is always normalized because this was accomplished in the first
step. That should be obvious. You don't need redundant rows, hence they
can be removed.
No I was wrong, they can't be removed. You might need those rows that have
duplicates in those columns.

--
Jamie Nelson

Jun 27 '08 #110
On Sat, 17 May 2008 11:24:49 -0500, Jamie Nelson wrote:
Quite right.

I misunderstood Jerry. He meant dups in those 2 columns only, not an
entire row. So this quote I posted is not relevant.

--
Jamie Nelson

Jun 27 '08 #111
On Sat, 17 May 2008 11:37:58 -0500, Jamie Nelson wrote:
>
Normalization can't hurt
I was incorrect, Jerry's table is normalized. It jsut has more columns.
--
Jamie Nelson

Jun 27 '08 #112
Disregard my post, Jerry was correct. I retract all my previous posts
in this thread.

On May 19, 1:04 am, "W. Jenkins" <grcassocia...@yahoo.comwrote:

Jun 27 '08 #113
On May 19, 1:21 am, "W. Jenkins" <grcassocia...@yahoo.comwrote:
Guillaume <ggra...@nospam.gmail.com.invalidwrote:
oxis...@yahoo.com a ?crit :
Here is the actual table structure:
Here is an example of my data:
Nice assert.
There is no "userid", "groupid", or "permission". This is a linking
table that relates entry_id to cat_id.
You wish. Still, you assume. And you're wrong. I mean you're wrong to
assume, cause you may be right about the table structure. Note the word,
"may".

The poster gave a concrete example of his data which is equivalent to
an instance of his problem. Most people can recognize a many-to-many
relationship.
No that's not right. My post was wrong. The OP gave a sample, which
could be interpreted in many different ways. It wouldn't be good to
assume this is what he meant. Better to use Jerry's solution instead
of adding new restrictions...

Jun 27 '08 #114
On May 19, 1:29 am, "W. Jenkins" <grcassocia...@yahoo.comwrote:
Jerry Stuckle <jstuck...@attglobal.netwrote:
How about this relationship:
groupid userid permission
1 1 read
1 1 write
1 1 delete
2 4 read
5 7 read
A perfectly normalized table

How do you know it's normalized? Maybe there are "extra columns"?
I was wrong.. Jerry said it was normalized then gave an example.
Pretty simple. It's clear what he was talking about.
Jun 27 '08 #115
Guillaume was right, I see that now. Sorry Guillaume, please accept my
apology and disregard my post. My objections weren't very sound. Of
course he is correct we can't assume too much about the poster's
problem because he was very vague. Attempting to shoe-horn his problem
into a particular relationship wouldn't be prudent and is unnecessary
given Jerry's solution works across all the reasonable scenarios.
On May 19, 12:55 am, "W. Jenkins" <grcassocia...@yahoo.comwrote:
Guillaume <ggra...@nospam.gmail.com.invalidwrote:
Jun 27 '08 #116
This account was a duplicate of Mitch Sherman. Sorry.

Disregard my posts.

On May 14, 5:13 am, williamitefa...@yahoo.com wrote:
On May 14, 3:32 am, Mitch Sherman <mitch.sher...@hush.aiwrote:
Jun 27 '08 #117
gary.l.si...@gmail.com wrote:
Tim Roberts wrote:

You are absolutely correct.
Not quite correct, because
Tim Roberts and Jerry were correct, I see that now. Sorry Tim for my
lame post.

Disregard my post please.

--
Gary L. Simms
gary.l.simms at gmail.com

Jun 27 '08 #118
Sorry, Corey Jansen (cc*****@gmail.com) is a sock puppet of Mitch
Sherman (mi***********@hush.ai).

Corey Jansen wrote:
I tried both queries, and the result is Jerry's method produces very
strange results. The normalized approach posted by petersprc does give
the expected result though.
Not correct. Mtruy post was wrong. Jerry's method is fine if you use
DISTINCT which he said. And of course this is a pathological example.
Peter's query needs to be modified if you want to use it without
creating an index first.

--
Corey Jansen
cc*****@gmail.com
Jun 27 '08 #119

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

Similar topics

4
by: Chuck100 | last post by:
I'm having problems with the output of the following script (I've simplified it):- select a.section,a.user,count(b.number),null from table a, table b where......... group by a.section,a.user...
12
by: Franklin P Patchey | last post by:
I have modified some script and think i have put a bit in that isn't "compliant" Is the bit marked below (towards the end) correct - should it be () and not ("") <SCRIPT LANGUAGE="JavaScript">...
2
by: ASallade | last post by:
Hello, I've scoured my books and the web, but am still daunted, hopefully some of the users in this newsgroup will have advice for my problem. I am not an experienced javascript programmer,...
3
by: Funnyweb | last post by:
When adding a field to a table using ALTER TABLE is it possible to check if the field already exits before the ADD command is run? If so how do I do this? Thanks Hamilton
2
by: JPL Verhey | last post by:
(i hope somebody (else) will read and have an idea! Thnx) Hi, With a script in a popup window, I want to check if certain content is present in a page loaded into the frame "main" of the...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
3
by: koutoo | last post by:
I have a code that writes to 2 seperate files. I keep getting a "list index out of range" error. The strange part is that when checking the files that I'm writing too, the script has already...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.