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):

    SEMrush
     
    NITRO23456, Aug 26, 2017 IP
    SEMrush
  2. Blank ™

    Blank ™ Well-Known Member

    Messages:
    224
    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:
    503
    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:
    23,633
    Likes Received:
    3,191
    Best Answers:
    89
    Trophy Points:
    615
    #4
    sarahk, Aug 26, 2017 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,622
    Likes Received:
    717
    Best Answers:
    151
    Trophy Points:
    420
    #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:
    726
    Likes Received:
    50
    Best Answers:
    31
    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