[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

12/04/2008 at 11:57AM PST, ID: 23958045
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.9

Conditional WHERE clause

Asked by 24Carat in SQL Query Syntax

Tags: MySQL

Hi Everybody,

i have this multi UNION select query performing on 1 table. However it doesn't seem to be working.
_________________________________________________
My goal is this:
eg.:

Table looks a little like this:
____________________
fname          ;artcode;klrcode
                    ;D1309;1
                    ;D1309;2
D1309-8.jpg ;D1309;8
                    ;D1310;1
D1310-2.jpg ;D1310;2
                    ;D1310;8
D1312-2.jpg ;D1312;2
                    ;D1313;1
D1313.jpg    ;D1313;2
                    ;D1314;1
D1314-2.jpg ;D1314;2
                    ;D1318;1
                    ;D1318;2
                    ;D1318;5
                    ;D1319;1
                    ;D1319;2
D1319-5.jpg ;D1319;5



Query result should be like this:
in this case 7 rows and
if an artcode has fname <> '' then the first one with an fname
                if none of a specific artcode has an fname then the first without an fname
_________________________
D1309-8.jpg ;D1309;8
D1310-2.jpg ;D1310;2
D1312-2.jpg ;D1312;2
D1313.jpg    ;D1313;2
D1314-2.jpg ;D1314;2
                    ;D1318;1
D1319-5.jpg ;D1319;5


When query containes only this:
D1309
D1310
D1312
D1313
D1314
D1318
D1319



When i started building i used a testing code like this one:
SELECT *, '3' As ExTFld, '0' As ExTFld2 FROM productlist WHERE artcode LIKE 'D1309' LIMIT 0,1 UNION
SELECT *, '3' As ExTFld, '0' As ExTFld2 FROM productlist WHERE artcode LIKE 'D1310' LIMIT 0,1 UNION
SELECT *, '3' As ExTFld, '0' As ExTFld2 FROM productlist WHERE artcode LIKE 'D1312' LIMIT 0,1 UNION
SELECT *, '3' As ExTFld, '0' As ExTFld2 FROM productlist WHERE artcode LIKE 'D1313' LIMIT 0,1 UNION
SELECT *, '3' As ExTFld, '0' As ExTFld2 FROM productlist WHERE artcode LIKE 'D1314' LIMIT 0,1 UNION
SELECT *, '3' As ExTFld, '0' As ExTFld2 FROM productlist WHERE artcode LIKE 'D1318' LIMIT 0,1 UNION
SELECT *, '4' As ExTFld, '6' As ExTFld2 FROM productlist WHERE artcode LIKE 'D1319' ORDER BY ExTFld2 ASC, fname DESC LIMIT 0, 7


ExtFld and ExtFld2 are 2 extra fields that are 2 be shown as a seperate fields






I've been trying and experimenting with all kinds of things
- my first thought was to use this ORDER BY fname DESC
ONLY this only works on the last SELECT because the others are LIMITED

- conditional WHERE clause was my second geuss althought it seems like i can't get it to work
eg:


SELECT *, '3' As ExTFld, '0' As ExTFld2 FROM productlist WHERE
CASE WHEN artcode LIKE 'D1309'  AND fname <> '' THEN  artcode LIKE 'D1309'  AND fname <> ''  ELSE  artcode LIKE 'D1309'  END
LIMIT 0,1 UNION
...
....

This is not good cause every line is shown when i would take away LIMIT 0,1 so in this case every first result is shown


Maybe i'm overlooking the problem.

Anybody got any clues?
[+][-]12/04/08 01:43 PM, ID: 23099811

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Query Syntax
Tags: MySQL
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 1
Solution Grade: A
 
 
[+][-]12/05/08 12:48 AM, ID: 23103295

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/05/08 01:08 AM, ID: 23103373

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/05/08 01:30 AM, ID: 23103467

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/05/08 01:32 AM, ID: 23103478

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/05/08 08:16 AM, ID: 23105992

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/05/08 08:19 AM, ID: 23106018

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_2_20070628