Avatar of rknevitt
rknevitt
 asked on

#1241 - Operand should contain 1 column MySQL error

HI, Im getting the following error when i run the below MySQL code

#1241 - Operand should contain 1 column(s)

The code causing problems is this, i basically want to get the field 'plate' where the stock.regdate falls between regyear.startdate and regyear.enddate

(SELECT regyear.plate, regyear.startdate, regyear.enddate FROM regyear WHERE 'stock.regdate' between regyear.startdate and regyear.enddate) as RegYear

When i remove the code from the rest of the query, run it on its own, substituting stock.regdate for '2004-09-02' it works perfectly.

What might i be doing wrong?

Cheers
Rob
SELECT
stock.id,
stock.registration,
stock.advertisedprice,
stock.datein,
stock.variant,
stock.mileage,
stock.exteriorname,
stock.interiorname,
stock.ispoa,
stock.ismoa,
stock.supplierid,
stock.statusid,
stock.typeid,
stock.buyerid,
stock.datepurchase,
stock.vin,
stock.enginenumber,
stock.buyprice,
stock.specification,
stock.regdate,
stock.datetaxexpire,
stock.datemotexpire,
stock.bodytypeid,
stock.fuelid,
stock.transmissionid,
stock.siteid,
stock.vatqualifying,
stock.owners,
stock.spec_leather,
stock.spec_metallic,
stock.spec_navigation,
stock.spec_bluetooth,
stock.spec_sunroof,
stock.spec_cd,
stock.spec_heatedseats,
stock.spec_xenons,
model.id,
model.makeid,
model.name,
make.id,
make.name,
exterior.id,
exterior.name,
interior.id,
interior.name,
status.name,
(SELECT DATEDIFF(CURRENT_DATE(),stock.datein)) as DaysInStock,
(SELECT regyear.plate, regyear.startdate, regyear.enddate FROM regyear WHERE 'stock.regdate' between regyear.startdate and regyear.enddate) as RegYear 
FROM
stock AS stock
INNER JOIN models AS model 
             ON model.id = stock.modelid
INNER JOIN makes AS make 
             ON make.id = model.makeid
LEFT JOIN exterior AS exterior 
             ON stock.exteriorid = exterior.id
LEFT JOIN interior AS interior
             ON stock.interiorid = interior.id
INNER JOIN status AS status
             ON stock.statusid = status.id
WHERE stock.id = 1

Open in new window

MySQL Server

Avatar of undefined
Last Comment
rknevitt

8/22/2022 - Mon
Umesh

My observation .. you shouldn't include column name in single quotes.. should be in back ticks ( ` )

Try below...(with back ticks ` )
SELECT
stock.id,
stock.registration,
stock.advertisedprice,
stock.datein,
stock.variant,
stock.mileage,
stock.exteriorname,
stock.interiorname,
stock.ispoa,
stock.ismoa,
stock.supplierid,
stock.statusid,
stock.typeid,
stock.buyerid,
stock.datepurchase,
stock.vin,
stock.enginenumber,
stock.buyprice,
stock.specification,
stock.regdate,
stock.datetaxexpire,
stock.datemotexpire,
stock.bodytypeid,
stock.fuelid,
stock.transmissionid,
stock.siteid,
stock.vatqualifying,
stock.owners,
stock.spec_leather,
stock.spec_metallic,
stock.spec_navigation,
stock.spec_bluetooth,
stock.spec_sunroof,
stock.spec_cd,
stock.spec_heatedseats,
stock.spec_xenons,
model.id,
model.makeid,
model.name,
make.id,
make.name,
exterior.id,
exterior.name,
interior.id,
interior.name,
status.name,
(SELECT DATEDIFF(CURRENT_DATE(),stock.datein)) as DaysInStock,
(SELECT regyear.plate, regyear.startdate, regyear.enddate FROM regyear WHERE `stock.regdate` between regyear.startdate and regyear.enddate) as RegYear 
FROM
stock AS stock
INNER JOIN models AS model 
             ON model.id = stock.modelid
INNER JOIN makes AS make 
             ON make.id = model.makeid
LEFT JOIN exterior AS exterior 
             ON stock.exteriorid = exterior.id
LEFT JOIN interior AS interior
             ON stock.interiorid = interior.id
INNER JOIN status AS status
             ON stock.statusid = status.id
WHERE stock.id = 1
 
 
 
### OR THIS ONE wiythout any back ticks or quotes
 
SELECT
stock.id,
stock.registration,
stock.advertisedprice,
stock.datein,
stock.variant,
stock.mileage,
stock.exteriorname,
stock.interiorname,
stock.ispoa,
stock.ismoa,
stock.supplierid,
stock.statusid,
stock.typeid,
stock.buyerid,
stock.datepurchase,
stock.vin,
stock.enginenumber,
stock.buyprice,
stock.specification,
stock.regdate,
stock.datetaxexpire,
stock.datemotexpire,
stock.bodytypeid,
stock.fuelid,
stock.transmissionid,
stock.siteid,
stock.vatqualifying,
stock.owners,
stock.spec_leather,
stock.spec_metallic,
stock.spec_navigation,
stock.spec_bluetooth,
stock.spec_sunroof,
stock.spec_cd,
stock.spec_heatedseats,
stock.spec_xenons,
model.id,
model.makeid,
model.name,
make.id,
make.name,
exterior.id,
exterior.name,
interior.id,
interior.name,
status.name,
(SELECT DATEDIFF(CURRENT_DATE(),stock.datein)) as DaysInStock,
(SELECT regyear.plate, regyear.startdate, regyear.enddate FROM regyear WHERE stock.regdate between regyear.startdate and regyear.enddate) as RegYear 
FROM
stock AS stock
INNER JOIN models AS model 
             ON model.id = stock.modelid
INNER JOIN makes AS make 
             ON make.id = model.makeid
LEFT JOIN exterior AS exterior 
             ON stock.exteriorid = exterior.id
LEFT JOIN interior AS interior
             ON stock.interiorid = interior.id
INNER JOIN status AS status
             ON stock.statusid = status.id
WHERE stock.id = 1

Open in new window

rknevitt

ASKER
still says the same error :( i just saw someone mention on the net that you cant have 2 columns in a sub query or something??
ASKER CERTIFIED SOLUTION
rknevitt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61