1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

SQL Query

Discussion in 'Programming' started by NITRO23456, Aug 26, 2017.

  1. #1
    Any ideas why this isn't working:

    
    SELECT
    `Item Type`,
    COUNT(*),
    FROM Stock 
    WHERE `Use Commenced By` = ""
    GROUP BY `Item Type`
    
    Code (markup):
    But this works fine:
    
    SELECT
    `Item Type`,
    COUNT(*),
    FROM Stock 
    GROUP BY `Item Type`
    
    Code (markup):
     
    NITRO23456, Aug 26, 2017 IP
  2. Blank ™

    Blank ™ Well-Known Member

    Messages:
    223
    Likes Received:
    18
    Best Answers:
    6
    Trophy Points:
    110
    #2
    Try using double quotes in the WHERE clause. Other than that, IDK.
     
    Blank ™, Aug 26, 2017 IP
  3. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    516
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Just get this

    Error[/B]
    [B]SQL query: [IMG]https://p3nlmysqladm001.secureserver.net/nld50/85/themes/original/img/b_help.png[/IMG]
    
    SELECT `Item Type` , COUNT( * ) , 
    FROM Stock
    WHERE 'Use Commenced By' = ""
    GROUP BY `Item Type` 
    LIMIT 0 , 30
    
    MySQL said: [IMG]https://p3nlmysqladm001.secureserver.net/nld50/85/themes/original/img/b_help.png[/IMG]
    
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Stock
    WHERE 'Use Commenced By' = ""
    GROUP BY `Item Type`
    
    LIMIT 0, 30' at line 4 
    Code (markup):
     
    NITRO23456, Aug 26, 2017 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #4
    sarahk, Aug 26, 2017 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    If that's what you get, whatever you're using to run that query "fixes" the quotes. Use another method / program / whatever.
     
    PoPSiCLe, Aug 27, 2017 IP
  6. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #6
    One thing I would advise against is using spaces in field names. Instead the better way is to use Camel Cased or Lower Case for the titles:

    Item_Type/item_type
    Use_Commenced_By/use_commenced_by

    I am not saying that it is wrong to have spaces, just not the norm.

    Other than that the original statement is fine, you use backticks to escape the column name in where not single quotes. Are you sure that the result set you are expecting exist?

    Also remove the comma after the last field you want count() as it is not needed.
     
    ThePHPMaster, Aug 30, 2017 IP