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 7674445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:44:19+00:00 2026-05-31T16:44:19+00:00

I have a nested query which when I execute in SQL server 2008 management

  • 0

I have a nested query which when I execute in SQL server 2008 management studio, it works perfectly, it outputs two results but when I try and do this in PHP I am receiving an error and I think it is to do with the PHP output.

So here is the query in SQL server which works, but I think this is not right:

select * from product_catalogue where catalogueid =(select catalogueid from products where productid = 1)  (select * from products where productid = 1)

Here is the complete query in PHP:

        $query3 = "select * from product_catalogue where catalogueid =(select catalogueid from products where productid = '" . $productid . "')  (select * from products where productid = '" . $productid . "')";                      

    $result3 = sqlsrv_query( $conn, $query3, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));

    if( $result3 === false)
    {
         echo "Error in query preparation/execution.\n";
         die( print_r( sqlsrv_errors(), true));
    }


        while( $obj = sqlsrv_fetch_object( $result3)) 
                    {

                        $prod_image = $obj->picturem;
                        $prod_id = $obj->catalogueID;
                        $prod_description = $obj->description;
                        $prod_price = $obj->product_price;
                        echo "<p>$prod_id" ;
                        echo "<br/>$prod_description" ;
                        echo "<br/>&pound;$prod_price"; 
                        echo "<br/><br/><img src='$prod_image'  width='200' height='400'/>"; 
                        echo "<br/><br/>";
                        }

The error I am receiving when running this query is this:

Error in query preparation/execution. Array ( [0] => Array ( [0] => 01000 [SQLSTATE] => 01000 [1] => 16954 [code] => 16954 [2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor. [message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Executing SQL directly; no cursor. ) [1] => Array ( [0] => 01S02 [SQLSTATE] => 01S02 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0]Cursor type changed [message] => [Microsoft][SQL Server Native Client 10.0]Cursor type changed ) ) 

I have been researching nested queries as well as looking through the PHP manual trying to learn more about how to output results, I just feel like because it works in SQL server management studio, doesn’t mean the syntax is correct. Any advice is appreciated.

  • 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-05-31T16:44:20+00:00Added an answer on May 31, 2026 at 4:44 pm

    This is actually two completely separate queries:

    select * from product_catalogue where catalogueid =(select catalogueid from products where productid = 1)  
    

    and

    (select * from products where productid = 1)
    

    The simplest way to do what you want is to join the tables in a single query – something like:

    select c.catalogueID, 
           c.product_name, 
           c.product_price, 
           c.description, 
           p.productID, 
           p.picturem, 
           p.picturew
    from product p
    join product_catalogue c on c.catalogueid = p.catalogueid
    where p.productid = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query which works perfectly: SELECT * FROM Customer WHERE SacCode IN
I have this query which works perfectly: SELECT * FROM Customer WHERE SacCode IN
I have the following Subsonic 3.0 query, which contains a nested NotIn query: public
I got a nested query which I'm trying to run; however I have to
I have a query which uses a complicated set of CASE statements, some nested,
I have an sql query pulling a few results from different tables, one of
I have a query which is crossing two tables select count(*) from ingenium.empevt, ingenium.evt
I have an sql query which calculates the number of distinct fileIds in a
I have an SQL query (generated by LINQ to Entities) which is roughly like
I have a LINQ query which is fetching a list of nested objects. from

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.