dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] sql problem

  1. #1
    Join Date
    Feb 2006
    Location
    india
    Posts
    680

    resolved [RESOLVED] sql problem

    Hi

    this is a continuation from my previous thread...I wish to continue from that thread but i have marked that one with resolved....anyway

    I have a product table where 4 records are there.

    pid(product id) is the primary key,autoincremental and cid is the category id.

    cid pid
    20 1
    20 2
    20 3
    20 4

    In another table named special there are 3 records.But in this table there is no primary key.here is also the same pid as in product table.

    pid discount
    1 10
    2 20
    3 30

    Now i want to show the all products either with discount or without discount
    so it will be like this

    pid discount
    1 10
    2 20
    3 30
    4 no discount //this text i can display.

    Now I am writing this query

    SELECT * from product LEFT JOIN special on product.pid = special.pid WHERE product.cid = $master_id;

    4 rows are displaying but one pid is not showing

    its looking like this

    pid discount
    1 10
    2 20
    3 30
    no discount //this text i can display and here the pid 4 is missing

    Can anyone please suggest me what should i do?

    Thanks in advance for your co-operation

    Raj

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    what do you mean by not displayed? how are you displaying it, just through the command line client or something else?

  3. #3
    Join Date
    Feb 2006
    Location
    india
    Posts
    680
    hi

    thanks for your reply...Its solved..

    I just altered the sql in this way:

    SELECT *,product .pid from product LEFT JOIN special on product.pid = special.pid WHERE product.cid = $master_id;

    thanks again........

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    i guess this goes back to avoiding using * in queries.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles