Jon McIntosh
Jon McIntosh

Reputation:

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

Upvotes: 0

Views: 706

Answers (3)

ravindrakhokharia
ravindrakhokharia

Reputation: 174

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';

Upvotes: 0

AvatarKava
AvatarKava

Reputation: 15453

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: http://dev.mysql.com/doc/refman/5.1/en/join.html

Upvotes: 2

Michael Mrozek
Michael Mrozek

Reputation: 175705

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 JOIN, which is an SQL feature

Upvotes: 1

Related Questions