473,769 Members | 5,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4692
On May 15, 4:08 am, vkay...@gmail.c om 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.c om wrote:
Jun 27 '08 #102
On May 15, 11:09 pm, oxis...@yahoo.c om 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.c om wrote:
On May 15, 10:13 pm, Jerry Stuckle <jstuck...@attg lobal.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.c om 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...@attg lobal.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.c om wrote:
Ron Doyle [oxision at yahoo.com]
Jun 27 '08 #106
On May 15, 10:51 pm, oxis...@yahoo.c om 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.c om wrote:
On May 15, 9:52 pm, Jerry Stuckle <jstuck...@attg lobal.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
gary.l.si...@gm ail.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 #110

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

Similar topics

4
9798
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 union select a.section,a.user,null,count(c.number) from table a, table c
12
1994
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"> <!-- hiding page=new Date(); if (page.getDate() == 1) document.write("<embed src='media/audio/waltzinblack.mp3' width='145'
2
1536
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, but have gotten my code to work well, without errors on IE, Opera and netscapes recent builds. While testing, I found that it doesnt execute on Netscape 4.7 In the head I have a script that creates a custom object/class for products,
3
1813
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
1805
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 frameset in the opener window. I started with something like this (what happens when the considions are met already works):
1
3720
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
0
5575
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
12
3014
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 the instructions and couldnt get the correct results. heres the code stuff... temperature=input("what is the temperature of the spam?") if temperature>50: print "the salad is properly cooked." else:
3
1536
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 iterated through and finished writing, yet the error stated implies that it hasn't? So how can it be, that my script has written to the files, yet the error is stating that it hasn't made it through the script? I'll have 15 files that I have...
0
9423
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,...
0
10210
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, 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...
0
10039
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 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...
1
9990
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,...
0
9860
tracyyun
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...
1
7406
isladogs
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...
0
6668
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();...
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.