Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:45:21+00:00 2026-06-09T10:45:21+00:00

I need to use subqueries to name columns in a query. I have written

  • 0

I need to use subqueries to name columns in a query. I have written a statement with subqueries in the SELECT section, but I am getting the following error message (returned from Codeigniter):

Error Number: 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 ‘(SELECT ps_url_name FROM product_selects WHERE ps_id = ‘1’), psc_opt_2 A’ at line 1

SELECT
    `psc_opt_1` AS (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '1'),
    `psc_opt_2` AS (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '2'),
    `psc_opt_3` AS (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '3'),
    `psc_opt_4` AS (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '4'),
    `psc_opt_5` AS (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '5')
FROM (`product_stock_control`)
WHERE `psc_prod_id` = '5'

Filename: models/products_model.php

Line Number: 602

Any ideas what is going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:45:23+00:00Added an answer on June 9, 2026 at 10:45 am

    AS is a column alias operator, meaning you are selecting these variables as an identifier. You cannot use the operator to identify a variable with a query.

    Reference: http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html

    Instead, you’ll need to reverse how you use the alias operator like so:

    SELECT
        (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '1') AS `psc_opt_1`,
        (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '2') AS `psc_opt_2`,
        (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '3') AS `psc_opt_3`,
        (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '4') AS `psc_opt_4`,
        (SELECT `ps_url_name` FROM `product_selects` WHERE `ps_id` = '5') AS `psc_opt_5`
    FROM (`product_stock_control`)
    WHERE `psc_prod_id` = '5'
    

    Ideally, you should avoid using subqueries (especially in this case) to avoid table-locking overhead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed Matlab r2010a on my computer I need use the function xlsread
Need to use own imaged markers instead built-in pins. I have several questions. 1.
I need to return average for each of 12 columns I have in a
I have a view where I need use 2 models because I'm trying to
I'm facing a hard time to get the following query: Let's say I have
I have two tables (Master, Responses) I need use the Master_Id field from the
I need to create native SQL query with couple of unions and subqueries. It'll
I have the following query which I found a modified version of it online.
Let's say I need to query the associates of a corporation. I have a
I have two tables users with columns: uid, name, mail, etc users_roles with columns:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.