Avatar of AXISHK
AXISHK

asked on 

TSQL query

Base on the TSQL below, what's the purpose of adding "MAX"  ? Can anyone think of any possible reason ? Does it mean it may return such records on PIC3, PIC2 and PIC1 and we use 'MAX' to restrict to one record ?

select inventbatchid,itemid,a2,a3,a4,
Tent,
max(case typeid when 'ImgS' then pic else '' end) as 'PIC3',
max(case typeid when 'sketchA' then pic else '' end) as 'PIC2',
max(case typeid when 'sketchB' then pic else '' end) as 'PIC1'  
into #tmp3 from #tmp2
MySQL ServerSQL

Avatar of undefined
Last Comment
HainKurt
SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Blurred text
THIS SOLUTION IS 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
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS 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.
Avatar of PortletPaul
PortletPaul
Flag of Australia image

I would go further about MySQL's default slackness on GROUP BY!
By default there is an "extension" which in my opinion leads to lazy code that can produce poor results.

see:
https://www.experts-exchange.com/questions/28500137/problem-sum-query-mysql-vb-net.html?anchorAnswerId=40270222#a40270222
and
http://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_only_full_group_by

However turning off the "extension" may affect existing scripts.
SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Blurred text
THIS SOLUTION IS 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.
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo