473,324 Members | 2,214 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,324 software developers and data experts.

What is wrong with this SQL Statement?

133 100+
Hi,

Please can someone help me with this. It is not returning any results but it should.

[PHP]SELECT * FROM listings WHERE (category = 'Weddings' or category2 = 'Weddings' or category3 = 'Weddings') AND (subcategory = 'DJs Discos and Karaoke' or subcategory2 = 'DJs Discos and Karaoke' or subcategory3 = 'DJs Discos and Karaoke') AND status = '1' ORDER BY ('premium', 'sdate')[/PHP]

Cheers,
Adam
Feb 28 '08 #1
6 1182
ronverdonk
4,258 Expert 4TB
This is a MySQL question, so I'll move the thread to that forum. - moderator

When 'premium' and 'sdate' are table columns, you don't specify any quotes around column names (back-ticks if you want to), so should sort by
Expand|Select|Wrap|Line Numbers
  1. ORDER BY premium, sdate
Ronald
Feb 28 '08 #2
nathj
938 Expert 512MB
Hi,

Please can someone help me with this. It is not returning any results but it should.

[PHP]SELECT * FROM listings WHERE (category = 'Weddings' or category2 = 'Weddings' or category3 = 'Weddings') AND (subcategory = 'DJs Discos and Karaoke' or subcategory2 = 'DJs Discos and Karaoke' or subcategory3 = 'DJs Discos and Karaoke') AND status = '1' ORDER BY ('premium', 'sdate')[/PHP]

Cheers,
Adam
Hi,

It's difficult to tell without seeing the data involved. Could it be a case sensitivity issue?

Try converting the fields to lowercase:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM listings WHERE 'weddings' IN(lower(category), lower(category2), lower(category3)) AND 'djs discos and karaoke' IN (lower(subcategory), lower(subcategory2), lower(subcategory3)) AND status = '1' ORDER BY ('premium', 'sdate')
  2.  
I have also modified the code sligtly but that shouldn't have anmy impact on it's own.

Cheers
nathj
Feb 28 '08 #3
ronverdonk
4,258 Expert 4TB
No, it is definitely the ORDER BY.

Ronald
Feb 28 '08 #4
nathj
938 Expert 512MB
No, it is definitely the ORDER BY.

Ronald
Hi,

Show my own lack of understanding here but how would an 'ORDER BY' affect the output in terms of what is retrieved? I thought it simply ordered the results byt the fields specified.

nathj
Feb 28 '08 #5
adamjblakey
133 100+
It was the ORDER BY that was causing the problem. It should have been e.g. ORDER BY premium ASC, sdate ASC

Cheers,
Adam
Feb 28 '08 #6
ronverdonk
4,258 Expert 4TB
Hi,

Show my own lack of understanding here but how would an 'ORDER BY' affect the output in terms of what is retrieved? I thought it simply ordered the results byt the fields specified.

nathj
nathj: Not when it is incorrectly specified. See Adam's answer: it was the ORDER BY.

Adam: glad this is solved. See you next time around.

ROnald
Feb 28 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
6
by: Daniel Rudy | last post by:
What is wrong with this program? When I try to compile it, I get the following error. Compiler is gcc on FreeBSD. strata:/home/dcrudy/c 1055 $$$ ->cc -g -oe6-3 e6-3.c e6-3.c: In function...
8
by: Brian Basquille | last post by:
Hello all, Bit of a change of pace now. As opposed to the typical questions regarding my Air Hockey game, am also working on a Photo Album which uses an Access Database to store information...
1
by: THY | last post by:
can anyone tell me what's wrong with this statement ? cn.execute("update table set data = 'test'") the asp.net keep telling me syntax error in update statement ... help me please ...
22
by: noridotjabi | last post by:
Okay. I'm quite embarased to be asking this but I cannot seem to get files to work. I don't know what the problem is. Is there something wrong with this: (file related) #include <stdio.h>...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
5
by: Ryan | last post by:
{"POINTID":77902,"MAPID":762,"LONG":-122.21654892,"LAT":"37.1834331019","CITY":"Boulder Creek","STATE":"CA","DIST":5745.4} I get an "invalid label" error... I'm kinda new to this. Thanks!
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
6
by: CTG | last post by:
"update set UPDATE-FLAG=false, UPDATE-DT= '10/09/2007 4:09:59 PM' WHERE ICCID='I1' " UPDATE_FLAG is a YES/NO ICCID is TEXT I have tried YES, NO as well but still fails,
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.