Results 1 to 2 of 2

Thread: MSQL Snippets that work at Powweb

  1. #1
    Former Spam Filter (EU) IanS's Avatar
    Join Date
    Mar 2004
    Location
    Washington (THE original UK one!)
    Posts
    12,964
    Rep Power
    30

    MSQL Snippets that work at Powweb

    As the title suggests, it's a thread for snippets that work.
    This is a Powweb customer
    helping Powweb customer forum.

    I am a customer just like you!!

    Some matters can only be answered by staff or support.
    Give it a go - ask here first!

  2. #2

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17
    A few hints for MYSQL JOINS:



    JOIN: You use join when you want to do two (or more) MYSQl queries in the one go.

    Example: Using the staff members email, You find what work area they belong to. Then you list all the staf in that area. The information is in the same table

    JOIN - WORKING CODE:

    Code:
    SELECT t2.*
    FROM `names` AS t1
    JOIN `names` AS t2 ON ( t1.WorkArea = t2.WorkArea )
    AND (
    t1.Email = '$email'
    )
    LIMIT 0 , 30

    JOIN - Problem: where to put quotes.

    Based on various MYSQL tutorials, it will show you various ways / where to put quotes. my working example

    - No quotes on column names (EG t2.* )
    - single quotes on values - eg $email
    - back-quotes (not sure of the exact name) on any table names.

    JOIN - PROBLEM: Duplicate table names:

    By default MySQL will return all columns for all tables if you use *. You will need to explicitly enter column names in your query to retrieve them the way you want. Use the query as follows:

    Incorrect:
    SELECT t1.* , t2.*
    SELECT all fields from table 1 and table 2.

    Correct: SELECT t1.Email, t1.Name
    SELECT the EMAIL column from table 1, and NAME column of table 1 - no duplicate columns in your result

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •