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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:09:38+00:00 2026-05-25T02:09:38+00:00

I have the following code: $sql = SELECT table.field, table2.field2 FROM table, table2; $stmt

  • 0

I have the following code:

    $sql = "SELECT table.field, table2.field2 FROM
                table, table2";
    $stmt = $this->db->prepare($sql);
    $stmt->execute();

    $x = $stmt->fetchAll(PDO::FETCH_ASSOC);

I know it is not enough information, but I do not understand why the code executes only if I comment the fetchAll line. When that line executes, I do not get anything, just blank browser, no errors or anything. In firebug the response is blank… What can it be??

  • 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-25T02:09:39+00:00Added an answer on May 25, 2026 at 2:09 am

    You are doing a Cartesian product of table and table2. This can be a HUGE amount of data.

    For each row in table, you are getting all the rows in table2. So if table has 100 lines, and table2 has 500 lines, your query will try to fetch 50.000 lines.

    You’ll either want a JOIN:

    SELECT table.field, table2.field2 
    FROM table 
    JOIN table2 
    ON table.field3 = table2.field3
    

    Or a UNION

    SELECT table.field AS FIELDNAME FROM table
    UNION ALL
    SELECT table2.field2 AS FIELDNAME FROM table2
    

    If a Cartesian product is really what you want, try adding a LIMIT and see if that works. Then later increase or remove the limit

    SELECT table.field, table2.field2 
    FROM table, table2 LIMIT 10
    

    Depending on what your tables contain (you indeed did not give enough info).

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

Sidebar

Related Questions

I have the following t-sql code which generates an error Declare @table TABLE (
I am using the following SQL query: Select * from table1 as t1, table2
I have the following code SELECT tA.FieldName As [Field Name], COALESCE(tO_A.[desc], tO_B.[desc], tO_C.Name, tA.OldVAlue)
I have the following sql query that fetches images from an establishment table. The
i have the following union query sql in my code (SELECT TableA.ID, TableB.Group, ''
I have the following SQL code that runs against a Change Request database. Each
I have the following code that fills dataTable1 and dataTable2 with two simple SQL
I have the following shortened classic ASP code that makes a SQL insert call...
I am debugging some code and have encountered the following SQL query (simplified version):
Following Uncle Bob's avice in Clean Code , I'd like to have no SQL

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.