Advertisement

07.05.2008 at 06:36AM PDT, ID: 23540626
[x]
Attachment Details

complicated mysql query

Asked by TDK777 in SQL Query Syntax, MySQL Server

Tags:

hello,
i am trying to write one query, but still getting not right results.
Here is how my table looks like:

id  |  country    |   number  |
 1   |       usa      |         3        |
  2  |      norway       |         3        |
3    |     palestine        |       3          |
 4   |     sweden        |       1         |
5    |    norway         |        2         |
6   | palestine          |        7          |
7 | estonia       |               2         |


I need to select the ones, which have "2" in field "number", but, if, the country do not have number "2", then to select countries which have "number" "3".

The result should be like this:

id      |country      |number      |
1      |usa            |3      |
3      |palestine      |3      |
5      |norway      |2      |
7      |estonia      |2      |

Start Free Trial
 
 
[+][-]07.05.2008 at 06:41AM PDT, ID: 21937061

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 06:46AM PDT, ID: 21937070

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 06:49AM PDT, ID: 21937076

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 06:58AM PDT, ID: 21937100

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 07:00AM PDT, ID: 21937107

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 07:03AM PDT, ID: 21937114

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 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 07:05AM PDT, ID: 21937121

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 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 07:06AM PDT, ID: 21937127

View this solution now by starting your 7-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

Zones: SQL Query Syntax, MySQL Server
Tags: mysql
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.05.2008 at 08:06AM PDT, ID: 21937294

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.05.2008 at 09:05AM PDT, ID: 21937461

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628