Click here to Skip to main content
15,904,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have an database with some tables in it. each two of the tables are related together. i want to ask how can i search in the database with one query and find the results of it with the rows of the other table that are related to it beside it with the same query?

for example i have 2 tables named "table1" with fields:'code, date, ...'
and a table called "related-to-table1" with fields:'code, text, id, ...'. The table's are related by code and in "table1", "code" is an auto increment field but in "related-to-table1" it's not and for each code in "table1" there could be more than one in the other table.

I want to see how can i search between a specific date in "table1" and select every row from the "related-to-table1" where its code in "table1" has the date we want?

sorry for the long question and my English!

thanks!
Posted

To retrieve the data between two tables, you do Join between them.
To know more about basics of SQL joins, visit http://www.w3schools.com/sql/sql_join.asp[^].
 
Share this answer
 
Comments
RaisKazi 21-Nov-11 12:28pm    
Simple short and correct. 5ed.
Using Join and Where clause for condition/filter on your Date-Column.

Using Joins

SQL WHERE Clause
 
Share this answer
 
v2
Comments
Abhinav S 21-Nov-11 12:29pm    
5! Thought almost same answer. :)
RaisKazi 21-Nov-11 12:31pm    
Yup, But "Where" Clause is additional. :)
Abhinav S 22-Nov-11 0:50am    
Yes. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900