Link to home
Create AccountLog in
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

Avatar of Umesh
Umesh
Flag of India image

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

Avatar of rknevitt
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
Avatar of rknevitt
rknevitt

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer