You are here: Re: Joining search queries « PHP Programming Language « IT news, forums, messages
Re: Joining search queries

Posted by Boris Stumm on 10/09/07 10:13

Alec wrote:
> $result = @mysql_query ("SELECT company, priority FROM table1 WHERE
> priority ='high' "); UNION; @mysql_query ("SELECT company, priority
> FROM table1 WHERE priority ='low' ");

First thing to remember: post readable code.

$result = @mysql_query("SELECT company, priority FROM table1
WHERE priority ='high' ");
UNION;
@mysql_query ("SELECT company, priority FROM table1
WHERE priority ='low' ");

Now it is quite visible what is happening. You only assign the
first query to $result.

Solution if the only priorities that exist are "high" and "low":

SELECT company, priority FROM table1;

Other solution:

SELECT company, priority FROM table 1
WHERE priority in ('high', 'low');

The less-than-optimal, but correct UNION-solution:

SELECT company, priority FROM table 1
WHERE priority ='high')
UNION
SELECT company, priority FROM table 1
WHERE priority = 'low');

You REALLY should read some SQL-Tutorial, because this is
really BASIC knowledge about SQL.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация