I have 2 tables, adds, and adds_filters
Here are my tables:
CREATE TABLE IF NOT EXISTS `adds` (
`addid` int(11) NOT NULL AUTO_INCREMENT,
`memberid` int(11) NOT NULL,
`isnew` int(11) NOT NULL,
`catid` int(11) NOT NULL,
`manufacturerid` int(11) NOT NULL,
`modelid` varchar(255) DEFAULT NULL,
`colorid` int(11) DEFAULT NULL,
`geographicareaid` int(45) NOT NULL,
`addtypeid` varchar(45) NOT NULL,
`addcreatedon` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`addvalidfrom` date NOT NULL,
`addvaliduntil` date NOT NULL,
`addcreatedfromip` varchar(255) NOT NULL,
`yearofmanufacturing` varchar(255) DEFAULT NULL,
`monthofmanufacturing` int(11) DEFAULT NULL,
`hoursused` int(11) DEFAULT NULL,
`cc2` int(11) DEFAULT NULL,
`horsepowers` int(11) DEFAULT NULL,
`metalic` tinyint(4) DEFAULT NULL,
`isdamaged` tinyint(4) DEFAULT NULL,
`price` float DEFAULT NULL,
`hasvat` tinyint(4) NOT NULL,
`canbenegotiated` tinyint(4) DEFAULT NULL,
`addtitle` varchar(255) DEFAULT NULL,
`addtext` text NOT NULL,
`youtubevideo` varchar(255) DEFAULT NULL,
`visible` tinyint(4) DEFAULT NULL,
`ff1` varchar(255) DEFAULT NULL,
`ff2` varchar(255) DEFAULT NULL,
`ff3` varchar(255) DEFAULT NULL,
`ff4` varchar(255) DEFAULT NULL,
PRIMARY KEY (`addid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=43 ;
CREATE TABLE IF NOT EXISTS `adds_filters` (
`addfilterid` int(11) NOT NULL AUTO_INCREMENT,
`addid` int(11) NOT NULL,
`filterid` int(11) NOT NULL,
PRIMARY KEY (`addfilterid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=45 ;
I have the following sql query that works like a charm, but I need to modify it:
SELECT DISTINCT a.addid
, a.memberid
, a.isnew
, a.catid
, a.manufacturerid
, a.modelid
, a.colorid
, a.geographicareaid
, a.addtypeid
, a.addcreatedon
, a.addvalidfrom
, a.addvaliduntil
, a.addcreatedfromip
, a.yearofmanufacturing
, a.monthofmanufacturing
, a.hoursused
, a.cc2
, a.horsepowers
, a.metalic
, a.isdamaged
, a.price
, a.hasvat
, a.canbenegotiated
, a.addtitle
, a.addtext
, a.youtubevideo
, a.visible
, a.ff1
, a.ff2
, a.ff3
, a.ff4
FROM adds a
JOIN adds_filters f
ON f.addid = a.addid
WHERE a.catid = 1
AND a.manufacturerid = 1
AND f.filterid IN (67,158)
My problem here is the following: if I add one more filter, (example 162) query should returns no results, since there is no add that has all 3 filters. Current query returns 3 rows, which all have the 67 and 158. Anyone can tell me how can I get the desired result?
Regards, John
Here is SQLfiddle
You should understand, that you gonna need to dynamicaly add the subqueries to each checked filterid.
Here is the query (you also can play with filterids in the main SELECT:
SELECT t1.*, t2.filterid as filterid2
FROM
(
SELECT DISTINCT a.*,
f.`filterid`
FROM adds a
JOIN adds_filters f
ON a.`addid` = f.`addid`
WHERE a.`catid` = 1
AND a.`manufacturerid` = 1
AND f.`filterid` = 67
) t1
JOIN
(
SELECT DISTINCT a.`addid`,
f.`filterid`
FROM adds a
JOIN adds_filters f
ON a.`addid` = f.`addid`
WHERE a.`catid` = 1
AND a.`manufacturerid` = 1
AND f.`filterid` = 158
) t2
ON t1.addid = t2.addid
JOIN
(
SELECT DISTINCT a.`addid`,
f.`filterid`
FROM adds a
JOIN adds_filters f
ON a.`addid` = f.`addid`
WHERE a.`catid` = 1
AND a.`manufacturerid` = 1
AND f.`filterid` = 162
) t3
ON t1.addid = t3.addid;
You should be able to simply change your join to the adds_filters component
FROM adds a
JOIN ( select addid
from adds_filters
where filterid in ( 67, 158, 162 )
group by addid
having count(*) = 3 ) f
ON f.addid = a.addid
WHERE a.catid = 1
AND a.manufacturerid = 1
By changing to a prequery of only those AddIDs that have all 3 components (via group by and having), it will only return those valid AddIDs
I would tend to go with the suggestion by DRapp, but if there are issues knowing how many filters there are in advance when building the SQL then another possibility would me one inner join per filter.
SELECT DISTINCT a.addid
, a.memberid
, a.isnew
, a.catid
, a.manufacturerid
, a.modelid
, a.colorid
, a.geographicareaid
, a.addtypeid
, a.addcreatedon
, a.addvalidfrom
, a.addvaliduntil
, a.addcreatedfromip
, a.yearofmanufacturing
, a.monthofmanufacturing
, a.hoursused
, a.cc2
, a.horsepowers
, a.metalic
, a.isdamaged
, a.price
, a.hasvat
, a.canbenegotiated
, a.addtitle
, a.addtext
, a.youtubevideo
, a.visible
, a.ff1
, a.ff2
, a.ff3
, a.ff4
FROM adds a
INNER JOIN adds_filters f1
ON f1.addid = a.addid AND f1.filterid = 67
INNER JOIN adds_filters f2
ON f2.addid = a.addid AND f2.filterid = 158
INNER JOIN adds_filters f3
ON f3.addid = a.addid AND f3.filterid = 162
WHERE a.catid = 1
AND a.manufacturerid = 1
Related
I'm trying to connect two tables and show the matching rows as columns.
ps_product table contains the values of the product, ps_image_shop contains the image values and id's linking to the product. What I would like to have is, showing matching rows as column at SQL result below.
Table 1 (ps_product) 1
Table 2 (ps_image_shop) 2
CURRENT SQL QUERY
SELECT SQL_CALC_FOUND_ROWS p.`id_product` AS `id_product`,
p.`reference` AS `reference`,
sa.`price` AS `price`,
p.`id_shop_default` AS `id_shop_default`,
p.`is_virtual` AS `is_virtual`,
pl.`name` AS `name`,
pl.`link_rewrite` AS `link_rewrite`,
sa.`active` AS `active`,
shop.`name` AS `shopname`,
image_shop.`id_image` AS `id_image`,
cl.`name` AS `name_category`,
0 AS `price_final`,
pd.`nb_downloadable` AS `nb_downloadable`,
sav.`quantity` AS `sav_quantity`,
IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`
FROM `ps_product` p
LEFT JOIN `ps_product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = 1 AND pl.`id_shop` = 1)
LEFT JOIN `ps_stock_available` sav ON (sav.`id_product` = p.`id_product` AND sav.`id_product_attribute` = 0 AND sav.id_shop = 1 AND sav.id_shop_group = 0 )
JOIN `ps_product_shop` sa ON (p.`id_product` = sa.`id_product` AND sa.id_shop = 1)
LEFT JOIN `ps_category_lang` cl ON (sa.`id_category_default` = cl.`id_category` AND cl.`id_lang` = 1 AND cl.id_shop = 1)
LEFT JOIN `ps_category` c ON (c.`id_category` = cl.`id_category`)
LEFT JOIN `ps_shop` shop ON (shop.id_shop = 1)
LEFT JOIN `ps_image_shop` image_shop ON (image_shop.`id_product` = p.`id_product` AND image_shop.id_shop = 1)
LEFT JOIN `ps_image` i ON (i.`id_image` = image_shop.`id_image`)
LEFT JOIN `ps_product_download` pd ON (pd.`id_product` = p.`id_product`)
WHERE (1 AND state = 1)
ORDER BY `id_product` desc
LIMIT 0, 100;
CREATE QUERIES
CREATE TABLE IF NOT EXISTS `ps_product` (
`id_product` int(10) unsigned NOT NULL,
`id_supplier` int(10) unsigned DEFAULT NULL,
`id_manufacturer` int(10) unsigned DEFAULT NULL,
`id_category_default` int(10) unsigned DEFAULT NULL,
`id_shop_default` int(10) unsigned NOT NULL DEFAULT '1',
`id_tax_rules_group` int(11) unsigned NOT NULL,
`on_sale` tinyint(1) unsigned NOT NULL DEFAULT '0',
`online_only` tinyint(1) unsigned NOT NULL DEFAULT '0',
`ean13` varchar(13) DEFAULT NULL,
`isbn` varchar(32) DEFAULT NULL,
`upc` varchar(12) DEFAULT NULL,
`ecotax` decimal(17,6) NOT NULL DEFAULT '0.000000',
`quantity` int(10) NOT NULL DEFAULT '0',
) ENGINE=InnoDB AUTO_INCREMENT=138 DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `ps_image_shop` (
`id_product` int(10) unsigned NOT NULL,
`id_image` int(11) unsigned NOT NULL,
`id_shop` int(11) unsigned NOT NULL,
`cover` tinyint(1) unsigned DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I'm trying to find all the values where empresas.id = (a number);
Here's my query:
SELECT empresas.nome, departamentos.nomeDepartamento,
funcionarios.nomeFuncionario, funcionarios.email, funcionarios.idFuncionario FROM empresas
INNER JOIN departamentos ON empresas.id = departamentos.idEmpresas
INNER JOIN funcionarios ON departamentos.id = funcionarios.idDepartamentos
ORDER BY empresas.nome ASC;
I've tried to put WHERE in the end, right after ASC :
...ORDER BY empresas.nome ASC WHERE id.empresas = 2;
And none of my tries have worked.
Tables:
CREATE TABLE `departamentos` (
`id` int(11) NOT NULL,
`idEmpresas` int(11) DEFAULT NULL,
`nomeDepartamento` varchar(30) DEFAULT NULL
)
CREATE TABLE `empresas` (
`id` int(11) NOT NULL,
`nome` varchar(30) DEFAULT NULL
)
CREATE TABLE `funcionarios` (
`idFuncionarios` int(11) NOT NULL,
`idDepartamentos` int(11) DEFAULT NULL,
`nomeFuncionario` varchar(30) DEFAULT NULL,
`email` varchar(30) DEFAULT NULL,
`senha` varchar(30) DEFAULT NULL
)
What i wanna do is JOIN those table to return empresas.nome, departamentos.nomeDepartamento,
funcionarios.nomeFuncionario, funcionarios.email, funcionarios.idFuncionario and then select then by empresas.
Thank you for your help!
SELECT empresas.nome, departamentos.nomeDepartamento,
funcionarios.nomeFuncionario, funcionarios.email, funcionarios.idFuncionario FROM empresas
INNER JOIN departamentos ON empresas.id = departamentos.idEmpresas
INNER JOIN funcionarios ON departamentos.id = funcionarios.idDepartamentos
WHERE empreas.id = 2 /* <=== The line to add */
ORDER BY empresas.nome ASC;
I've a complex query. And I'm freeze on position :(.
Here is my tables.
users:
CREATE TABLE `users` (
`id` tinyint(4) NOT NULL,
`office_name` varchar(255) DEFAULT NULL,
`district_id` int(10) DEFAULT NULL,
`upazilla_id` int(10) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`mobile` varchar(11) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(100) NOT NULL,
`type` varchar(10) NOT NULL,
`del_status` tinyint(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE `service` (
`id` int(10) NOT NULL,
`recipient_number` int(50) NOT NULL,
`date` date NOT NULL,
`office_id` int(10) NOT NULL,
`del_status` tinyint(1) NOT NULL,
`creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `service_list` (
`id` int(3) NOT NULL,
`service_name` varchar(50) NOT NULL,
`del_status` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `service_transaction` (
`id` int(10) NOT NULL,
`service_transaction_id` int(50) NOT NULL,
`service_id` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
here, service-id = service_transaction.service_transaction_id .
I worte a query:
select users.id, users.office_name,service_transaction.service_id , COUNT(service_transaction.service_id) as service_total
from users
LEFT JOIN service on users.id = service.office_id
LEFT JOIN service_transaction on service_transaction.service_transaction_id = service.id
WHERE( users.del_status = 0 and users.type='agency')
GROUP BY users.office_name , users.id, service_transaction.service_id
It return:
id office_name Service_id service_total
=============================================
2 Ctg Office 2 2
2 Ctg Office 3 4
2 Ctg Office 4 3
7 Dhaka Office NULL 0
But My Desire output is:
id office_name Service_id service_total
=============================================
2 Ctg Office 2 2
2 Ctg Office 3 4
2 Ctg Office 4 3
2 Ctg Office 5 0
2 Ctg Office 6 0
7 Dhaka Offc 2 0
7 Dhaka Offc 3 0
7 Dhaka Offc 4 0
7 Dhaka Offc 5 0
7 Dhaka Offc 6 0
It means, i've to show all services under each office, if no service, count should be zero.
select temp.id office_id , temp.office_name, temp.svcic ,count(service_transaction.service_id) as service_total, count(recipient.id) as total_count from (select users.id, users.office_name ,service_list.id svcic from users,service_list WHERE users.del_status = 0 and users.type='agency' ) temp LEFT JOIN service on temp.id = service.office_id and service.del_status=0 LEFT JOIN service_transaction on service_transaction.service_id = temp.svcic and service_transaction.service_transaction_id=service.id right outer JOIN recipient on recipient.office_id = temp.id group by temp.id , temp.office_name, temp.svcic ORDER BY temp.id,temp.office_name
please try the above code.
for more readable, you should maintain intend
Try this if not solve then let me know you data in table service and service_transaction table.
SELECT users.id, users.office_name,service_transaction.service_id , SUM(IF(service.id IS NULL, 0, 1)) as service_total
from users
JOIN service on users.id = service.office_id
JOIN service_transaction on service_transaction.service_transaction_id = service.id
WHERE( users.del_status = 0 and users.type='agency')
GROUP BY users.office_name , users.id, service_transaction.service_id
select users.id, users.office_name,service_transaction.service_id , COUNT(service_transaction.service_id) as service_total
from users
JOIN service
LEFT JOIN service_transaction on service_transaction.service_transaction_id = service.id
WHERE( users.del_status = 0 and users.type='agency')
GROUP BY users.office_name , users.id, service_transaction.service_id
Try above query.
I Have closing balances in Akey table and i have pool id in cpp table i want to update value of Bppd key_amount column with akey closing_balance but before
that i have to check the default_pool='ACTIVE' from table cpp
sample tables are mentioned
TABLE Akey (
`id` int(11) NOT NULL,
`serial_key` varchar(82) DEFAULT NULL,
`closing_balance` double(20,2) DEFAULT '0.00',
`product_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
)
TABLE Bppd(
`id` int(11) NOT NULL AUTO_INCREMENT,
`pool_id` int(11) DEFAULT NULL,
`product_id` int(11) DEFAULT NULL,
`akey_id` int(11) DEFAULT NULL,
`key_amount` double DEFAULT '0',
`working_balance` double DEFAULT '0',
PRIMARY KEY (`id`)
)
TABLE Cpp (
`id` int(11) NOT NULL AUTO_INCREMENT,
`akey_id` int(11) DEFAULT NULL,
`pool_id` int(11) DEFAULT NULL,
`default_pool` varchar(15) DEFAULT NULL,
PRIMARY KEY (`id`)
)
I have Following query
UPDATE `Bppd` ppd
JOIN AKey kk ON ppd.`akey_id` = kk.`id`
JOIN `Cpp` pp ON pp.`akey_id` = kk.`id` AND pp.`default_pool` = 'ACTIVE' AND ppd.`akey_id` = pp.`akey_id`
SET ppd.`key_amount`= kk.`closing_balance`
Try this
UPDATE Bppd b INNER JOIN Akey a on a.id = b.akey_id AND a.product_id = b.product_id
INNER JOIN Cpp c ON b.key_id = c.akey_id AND b.pool_id = c.pool_id
SET b.key_amount = a.closing_balance
WHERE c.default_pool='ACTIVE'
Or this:
UPDATE Bppd b SET key_amount = (SELECT closing_balance FROM Akey a WHERE a.id = b.akey_id and a.product_id = b.product_id)
WHERE EXISTS (
SELECT 1 FROM Cpp c
WHERE b.akey_id = c.akey_id AND b.pool_id = c.pool_id
AND c.default_pool='ACTIVE'
)
AND EXISTS (
SELECT 1 FROM Akey a
WHERE a.id = b.akey_id and a.product_id = b.product_id
)
I'm running MySQL 5.0.88 and have a search which I'm running a presearch to determine number of records,. min-max values as well as element strings of distinct values.
A result of the query will look like this:
records min-price max-price sizeRange colorRange
1234 9.00 124.00 S,M,L,XL red,blue,white,orange
My query looks like this:
SELECT COUNT(recordcount) AS total_records
, MIN(min_price_ek) AS ek_min
, MAX(max_price_ek) AS ek_max
, SUBSTRING_INDEX( GROUP_CONCAT( DISTINCT sizeRange ), ',', 10 ) AS sz_rng
, SUBSTRING_INDEX( GROUP_CONCAT( DISTINCT colorRange ), ',', 16 ) AS cl_rng
FROM (SELECT a.id AS recordcount
, a.nos
, a.nos_anzeige
, MAX(<cfif variables.preislisten neq "">IFNULL(p.ek, a.preis_ek)<cfelse>a.preis_ek</cfif>) AS max_price_ek
, MIN(<cfif variables.preislisten neq "">IFNULL(p.ek, a.preis_ek)<cfelse>a.preis_ek</cfif>) AS min_price_ek
, a.groesse AS sizeRange
, zu.systemfarbe AS colorRange
FROM artikelstammdaten a
LEFT JOIN farbenzuordnung zu
ON a.farbe = zu.farbe
WHERE a.aktiv = "ja"
AND a.artikelnummer LIKE <cfqueryparam value="#art#" cfsqltype="cf_sql_varchar">
GROUP BY a.iln, a.artikelnummer, a.preis_aktuell, a.artikelbezeichnung
HAVING (( sum(a.bestand) != 0 ) OR (a.nos = "ja" AND a.nos_anzeige = "ja" ))
) AS temp
This works ok, but I'm still having trouble with selecting all available sizes/colors. I'm getting some values, but not all.
My table looks like this:
CREATE TABLE dummy (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`iln` VARCHAR(13) NULL DEFAULT NULL,
`ean` VARCHAR(35) NULL DEFAULT NULL,
`artikelnummer` VARCHAR(35) NULL DEFAULT NULL,
`preis_ek` DECIMAL(12,2) NULL DEFAULT NULL,
`preis_vk` DECIMAL(12,2) NULL DEFAULT NULL,
`firma` VARCHAR(35) NULL DEFAULT NULL,
`nos` VARCHAR(4) NULL DEFAULT NULL,
`nos_anzeige` VARCHAR(4) NULL DEFAULT NULL,
`aktiv` VARCHAR(4) NULL DEFAULT NULL,
`bestand` DECIMAL(10,0) NULL DEFAULT '0'
)
So an product will be stored in the table with one entry per size like so:
product_id ean size price
1234 111111111111 S 9.99
1234 111111111112 M 9.99
1234 111111111113...
From what I'm getting back in MySQL, I think I'm only selecting the first size (S) of articles and create a GROUP_CONCAT of all DISTINCT first sizes vs a GROUP_CONCAT of all DISTINCT sizes of the recordset`.
Question:
Can someone give me a pointer on how I need to tweak my GROUP_CONCAT?
Thanks!
This is the query I'm currently testing with
SELECT COUNT(recordcount) AS total_records
, MIN(min_price_ek) AS ek_min
, MAX(max_price_ek) AS ek_max
, SUBSTRING_INDEX( GROUP_CONCAT( DISTINCT sizeRange ), ',', 10 ) AS sz_rng
, SUBSTRING_INDEX( GROUP_CONCAT( DISTINCT colorRange ), ',', 16 ) AS cl_rng
FROM (SELECT a.id AS recordcount
, a.nos
, a.nos_anzeige
, MAX(a.preis_ek) AS max_price_ek
, MIN(a.preis_ek) AS min_price_ek
, a.groesse AS sizeRange
, zu.systemfarbe AS colorRange
FROM artikelstammdaten a
LEFT JOIN farbenzuordnung zu
ON a.farbe = zu.farbe
WHERE a.aktiv = "ja"
AND a.artikelnummer LIKE "%402%"
GROUP BY a.iln, a.artikelnummer
HAVING (( sum(a.bestand) != 0 ) OR (a.nos = "ja" AND a.nos_anzeige = "ja" ))
) AS temp
I have removed the 3rd table (currency lookup/leftjoin), because results are false with or without it. This is the remaining two tables:
** artikelstammdaten = product data **
CREATE TABLE dummy (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`iln` VARCHAR(13) NULL DEFAULT NULL,
`ean` VARCHAR(35) NULL DEFAULT NULL,
`artikelnummer` VARCHAR(35) NULL DEFAULT NULL,
`groesse` VARCHAR(10) NULL DEFAULT NULL,
`farbe` VARCHAR(35) NULL DEFAULT NULL,
`preis_ek` DECIMAL(12,2) NULL DEFAULT NULL,
`preis_vk` DECIMAL(12,2) NULL DEFAULT NULL,
`preis_aktuell` DECIMAL(12,2) NULL DEFAULT NULL,
`marke` VARCHAR(35) NULL DEFAULT NULL,
`nos` VARCHAR(4) NULL DEFAULT NULL,
`nos_anzeige` VARCHAR(4) NULL DEFAULT NULL,
`aktiv` VARCHAR(4) NULL DEFAULT NULL,
`modus` VARCHAR(4) NULL DEFAULT NULL,
`bestand` DECIMAL(10,0) NULL DEFAULT '0'
)
** global colors / farbenzuordnung **
CREATE TABLE dummy (
`ILN` VARCHAR(13) NOT NULL,
`farbe` VARCHAR(35) NOT NULL,
`systemfarbe` VARCHAR(35) NOT NULL,
`systemfarbe_en` VARCHAR(35) NOT NULL
)
I'm testing with a single product right now (402). The product has 4 sizes and two colors, so this is 8 records in the database. Running the query on it should return s,m,l,xl for sizes and red, black for colors as Group__concat. However I'm only getting (arbitraty?) s and red as results.
Still clueless as to why.
You can use query as follows using GROUP_CONCAT along with ORDER BY CLAUSE,
Note: you need to define the criteria in following query based on your requirements
SELECT COUNT(recordcount) AS total_records
, MIN(min_price_ek) AS ek_min
, MAX(max_price_ek) AS ek_max
, SUBSTRING_INDEX( GROUP_CONCAT( DISTINCT sizeRange ORDER BY [criteria]), ',', 20 ) AS sz_rng
, SUBSTRING_INDEX( GROUP_CONCAT( DISTINCT colorRange ORDER BY [criteria]), ',', 20 ) AS cl_rng
FROM (SELECT a.id AS recordcount
, a.nos
, a.nos_anzeige
, MAX(<cfif variables.preislisten neq "">IFNULL(p.ek, a.preis_ek)<cfelse>a.preis_ek</cfif>) AS max_price_ek
, MIN(<cfif variables.preislisten neq "">IFNULL(p.ek, a.preis_ek)<cfelse>a.preis_ek</cfif>) AS min_price_ek
, a.groesse AS sizeRange
, zu.systemfarbe AS colorRange
FROM artikelstammdaten a
LEFT JOIN farbenzuordnung zu
ON a.farbe = zu.farbe
WHERE a.aktiv = "ja"
AND a.artikelnummer LIKE <cfqueryparam value="#art#" cfsqltype="cf_sql_varchar">
GROUP BY a.iln, a.artikelnummer, a.preis_aktuell, a.artikelbezeichnung
HAVING (( sum(a.bestand) != 0 ) OR (a.nos = "ja" AND a.nos_anzeige = "ja" ))
) AS temp
Hope it helps...