Jump to content

sqlmc

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Posts posted by sqlmc

  1. It looks like your using a varialbe for an alias. Try this.

     

    
    $sql11 =  "SELECT Company FROM Enq WHERE Enqid='$enq'
    UNION
    SELECT Company FROM Visit WHERE Visitid='$enq'";
    
    $result11 = mysql_query($sql11) or die (mysql_error());
    
    $myrow11 = mysql_fetch_array($result11);
    $company = $myrow11["Company"];
    
    

     

    Also what is the datatype for Visitid and Enqid? You're using single quotes, but if the field is numeric then this may cause an error. If these fileds are INTEGER for example remove the single quotes from the WHERE clause.

  2. Try adding the remaining selected attributes to your group by clause. So it would go something like this.

     

    Select distinct
    labor.Dept AS DEPT,
    labor.Job AS MS,
    countsheet.PART_NUMBER,
    Sum(labor.Total) AS DEPT_HOURS,
    countsheet.TOTAL AS TOTAL_QTY,
    countsheet.DUE AS UNCOMP_QTY,
    countsheet.NET AS COMP_QTY
    From
    labor,countsheet
    Where
    labor.Job = countsheet.MS
    Group By
    labor.Job,
    labor.Dept,
    countsheet.PART_NUMBER,
    countsheet.TOTAL ,
    countsheet.DUE ,
    countsheet.NET 
    Order By
    countsheet.MS Asc
    ;
    

     

    Oh, and I'm not seeing where countsheet.MS is being selected. Using an attrute in an Order By cluase that hasn't been selected may cause unexpected results.

     

     

     

  3. I would try removing the single quotes from the table and attribute names. Also your using a LIKE statement without a wildcard. So try something like this.

     

    
    $result = mysql_query("SELECT *  FROM general  WHERE header LIKE '%header%' " );
    
    

     

    In this example you should get results from your talbe where the attribute header contains a value with the string 'header' within it.

  4. Is your table structure for Enq and Visit is the same? If not, the UNION with a SELECT * may cause problems. If you only need a particualr value, or even multiple values try using aliases that match and that should work. So it would go something like this.

     

    SELECT Attribute_A as NeededValue
    FROM Enq
    WHERE Enqid='$enq'
    
    UNION
    
    SELECT Attribute_B as NeededValue
    FROM Visit 
    WHERE Visitid='$enq
    

  5. At what level of information are you looking for? If you using a newer version of MySQL you might try nested subquireis in your joins and then have each subquery use count(*), but can the information you're looking for be counted only once or does it require more than one value?

  6. I would try using an alias so it would go something like this:

     

    SELECT SUM( boardfee ) AS board_sum

    FROM boarded

    WHERE boarder = 'Duli'";

     

    /*************************************************************/

     

    As for summing the two columns it would go something like this:

     

    SELECT SUM( boardfee ) + SUM(ExtraFees) AS total_sum

    FROM boarded

    WHERE boarder = 'Duli'";

     

    /*************************************************************/

     

    Something else you may want to use with this or any other aggregate function is a group by clause.

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.