syntax join

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    syntax join

    hello

    i need help with join syntax here.anybody can plz do join syntax of

    Return the First Name, Last Name, Product Name, and Sale Price for all products sold in
    the month of October 2005.

    i want join syntax. inner join is same as join.so i want join only.not outer or cross.


    i did but i am facing error. i did

    PHP Code:
    select customers.firstname,lastnameproducts.pname,sales.sprice from sales join products on sales.pid=products.pid where sdate between '2005-10-01' and '2005-10-31'






    PHP Code:

    --
    -- 
    Table structure for table `customers`
    --

    CREATE TABLE IF NOT EXISTS `customers` (
      `
    cidint(20NOT NULL AUTO_INCREMENT,
      `
    firstnamevarchar(50) DEFAULT NULL,
      `
    lastnamevarchar(50) DEFAULT NULL,
      `
    cityvarchar(50) DEFAULT NULL,
      `
    statevarchar(2) DEFAULT NULL,
      `
    zipvarchar(10) DEFAULT NULL,
      
    PRIMARY KEY (`cid`)
    ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;

    --
    -- 
    Dumping data for table `customers`
    --

    INSERT INTO `customers` (`cid`, `firstname`, `lastname`, `city`, `state`, `zip`) VALUES
    (1'chintan''patel''anand''gj''388001'),
    (
    2'paresh''prajapati''nadiad''gj''387001'),
    (
    3'pragnesh''patel''surat''gj''395008'),
    (
    4'nilesh''dharsandia''mumbai''mh''400002'),
    (
    5'sonal''patel''mumbai''mh''400002'),
    (
    6'harshal''patel''mogri''gj''388345'),
    (
    7'prakash''rathod''mogri''gj''388345'),
    (
    8'aarzoo''dodhiya''rajkot''gj''360003'),
    (
    9'heta''dave''varanasi''up''221002'),
    (
    10'nikita''dave''varanasi''up''221002'),
    (
    11'vaibhav''dave''varanasi''up''221002'),
    (
    12'paresh''patel''pune''mh''411001'),
    (
    13'prakash''patel''pune''mh''411001'),
    (
    14'sandhya''patel''hyderabad''ap''500031'),
    (
    15'divesh''patel''bangalore''ka''560002'),
    (
    16'payal''shah''bangalore''ka''560002'),
    (
    17'priyanka''rana''anand''gj''388001'),
    (
    18'sanket''dhebar''v.v.nagar''gj''388121'),
    (
    19'puja''shah''varanasi''up''221002'),
    (
    20'priya''shah''varanasi''up''221002');

    -- --------------------------------------------------------

    --
    -- 
    Table structure for table `products`
    --

    CREATE TABLE IF NOT EXISTS `products` (
      `
    pidint(20NOT NULL AUTO_INCREMENT,
      `
    productnamevarchar(20) DEFAULT NULL,
      `
    recommendedpricevarchar(20) DEFAULT NULL,
      `
    categoryvarchar(10) DEFAULT NULL,
      
    PRIMARY KEY (`pid`)
    ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=;

    --
    -- 
    Dumping data for table `products`
    --

    INSERT INTO `products` (`pid`, `productname`, `recommendedprice`, `category`) VALUES
    (1'dvd''105''livingroom'),
    (
    2'microwave''98''kitchen'),
    (
    3'monitor''200''office'),
    (
    4'speakers''85''office'),
    (
    5'refrigerator''900''kitchen'),
    (
    6'vcr''165''livingroom'),
    (
    7'coffee pot''35''kitchen');

    -- --------------------------------------------------------

    --
    -- 
    Table structure for table `sales`
    --

    CREATE TABLE IF NOT EXISTS `sales` (
      `
    sidint(20NOT NULL AUTO_INCREMENT,
      `
    pidint(20) DEFAULT NULL,
      `
    cidint(20) DEFAULT NULL,
      `
    spricevarchar(20) DEFAULT NULL,
      `
    sdatevarchar(20) DEFAULT NULL,
      
    PRIMARY KEY (`sid`)
    ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=32 ;

    --
    -- 
    Dumping data for table `sales`
    --

    INSERT INTO `sales` (`sid`, `pid`, `cid`, `sprice`, `sdate`) VALUES
    (111'130''2005-06-2014'),
    (
    222'97''2005-06-19'),
    (
    333'200''2005-09-20'),
    (
    444'80''2005-03-2022'),
    (
    555'899''2005-01-23'),
    (
    666'150''2005-03-24'),
    (
    737'209''2005-03-10'),
    (
    848'90''2005-08-11'),
    (
    969'130''2005-08-12'),
    (
    10214'85''2005-12-13'),
    (
    11315'240''2005-05-14'),
    (
    12117'87''2005-07-19'),
    (
    13218'99''2005-09-20'),
    (
    14619'150''2005-07-22'),
    (
    1555'900''2005-03-06'),
    (
    1646'86''2005-04-07'),
    (
    1727'88''2005-11-08'),
    (
    1838'198''2005-05-09'),
    (
    1919'150''2005-10-10'),
    (
    20614'99''2005-05-09'),
    (
    21615'104''2005-09-20'),
    (
    22414'90''2005-07-22'),
    (
    2311'130''2005-03-06'),
    (
    2422'102''2005-04-07'),
    (
    2513'114''2005-11-08'),
    (
    2654'1000''2005-05-09'),
    (
    2755'1100''2005-10-10'),
    (
    2836'285''2005-06-11'),
    (
    2927'87''2005-10-12'),
    (
    3038'300''2005-07-13'),
    (
    31320'205''2005-12-31'); 
    Attached Files
    Last edited by thunderwap; 11.12.14, 05:37.
    sigpic

    WANT GOOD CHEAP HOSTING WITH 99% UPTIME? THEN PM ME FOR DETAILS!!

    #2
    PHP Code:
    select c.firstname,
        
    c.lastname,
        
    p.pname,
        
    s.sprice 
    from sales s
        join products p
        on s
    .pid=p.pid 
        join customers c
        on p
    .pid s.pid

    where s
    .sdate between '2005-10-01' and '2005-10-31'//between needs to be an integer not a string 

    Comment


      #3
      Originally posted by something else View Post
      PHP Code:
      select c.firstname,
      c.lastname,
      p.pname,
      s.sprice
      from sales s
      join products p
      on s
      .pid=p.pid
      join customers c
      on p
      .pid s.pid

      where s
      .sdate between '2005-10-01' and '2005-10-31'//between needs to be an integer not a string 

      my problem got solved.thanks.

      it should be "from sales join products on sales.pid=products.pid"

      i.e

      Code:
      select customers.firstname,lastname, products.productname,sales.sprice
      from sales
      join products on sales.pid=products.pid
      join customers on sales.cid=customers.cid
      where date(sales.sdate) between '2005-10-01' and '2005-10-31';
      and there should be date(sales.sdate) between....... instead s.sdate between.......

      if sales is not defined before sdate then it will not take sales date and shows error.i forgot this join syntax and so i refered normalization and join syntax again.

      thank you for help mate.
      Last edited by thunderwap; 15.12.14, 07:53.
      sigpic

      WANT GOOD CHEAP HOSTING WITH 99% UPTIME? THEN PM ME FOR DETAILS!!

      Comment

      Working...
      X