Php fetch rows from multiple MySQL tables


What I want to do is get the data from two different tables (table1 and table2) where row1 = 'test' in both of the tables


You'll want to use an INNER JOIN here - something along these lines (can't tell you for sure since you didn't give the structure of your tables)...

SELECT * FROM thread t INNER JOIN post_display pd ON pd.threadid = t.threadid WHERE t.threadid = 2 ORDER BY t.threadid DESC

Note: SELECT * can be very bad if you're selecting a bunch of fields you're never going to need. Once you have the query working, narrow down your select to the specific fields you're looking to work with.

More info on JOIN syntax for MySQL is available here: <a href="http://dev.mysql.com/doc/refman/5.1/en/join.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/en/join.html</a>


I'm not quite sure what you're asking, but if you want to fetch columns from multiple tables at once (and it sounds like you're saying rows when you mean columns) you probably want a <a href="http://dev.mysql.com/doc/refman/5.0/en/join.html" rel="nofollow">JOIN</a>, which is an SQL feature


I am not getting what you are asking about.. but.. i can give u suggestion on you asked question.. u can try this.. have a look

SELECT * FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.t1id WHERE t1.row1 like 'test' AND t2.row like 'row';


  • Cannot terminate threads
  • Closing thread using ExitThread - C
  • Listen to the 'change' even of an element in the shadow DOM
  • Notepad++ - delete all lines with certain text
  • Color time-series based on column values in pandas
  • change color of jstree node
  • node.js POST request fails
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Looking for good analogy/examples for monitor verses semaphore
  • ViewController With Transparent Background Entering Current ViewController With Push Transition
  • Assign variable to the value in HTML
  • Display images in Django
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • Moving mysql files across servers
  • Bad request using file_get_contents for PUT request in PHP
  • Error when parsing timestamp with pandas read_csv
  • $wpdb not working in file of WordPress plugin
  • How to use an array of arrays with array_map(…) in PHP?
  • Paperclip, set path outside of rails root folder
  • R - Combining Columns to String Based on Logical Match
  • Get one-time binding to work for ng-if
  • javaw.exe and eclipse startup problems
  • Running a C# exe file
  • Do create extension work in single-user mode in postgres?
  • How to get next/previous record number?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Comma separated Values
  • Android Studio and gradle
  • SQL merge duplicate rows and join values that are different
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • How do you join a server to an Active Directory (domain)?
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • need help with bizarre java.net.HttpURLConnection behavior
  • How does Linux kernel interrupt the application?
  • Converting MP3 duration time
  • How to load view controller without button in storyboard?