I have two table and want to fetch data from them.
This query working fine:
"Select * from myads join users on myads.id = users.id";
but the problem is I want to use one of the field as counter
For the Single table this works for me:
"SELECT *,(30-DATEDIFF(now(),updateDate)) as counter FROM myads";
Now, my question is how can i combine this two querys.. any help will be helpful.
Join two table and fetch data!
Moderator: General Moderators
-
nshthmistry
- Forum Newbie
- Posts: 3
- Joined: Fri Feb 28, 2014 5:33 am
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Join two table and fetch data!
Not sure what you mean by "use one of the field as counter"? Seems like you could put the DATEDIFF() constraint in the WHERE. If you want to consolidate values then use GROUP BY.
(#10850)
-
nshthmistry
- Forum Newbie
- Posts: 3
- Joined: Fri Feb 28, 2014 5:33 am
Re: Join two table and fetch data!
okay, i put it different way..
How can i use this query:
"SELECT *,(30-DATEDIFF(now(),updateDate)) as counter FROM myads";
but for the two tables..
How can i use this query:
"SELECT *,(30-DATEDIFF(now(),updateDate)) as counter FROM myads";
but for the two tables..
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Join two table and fetch data!
You mean like:
"SELECT myads.*,(30-DATEDIFF(now(),myads.updateDate)) as counter, othertable.somefield FROM myads JOIN othertable ON myads.id=othertable.myads_id";
"SELECT myads.*,(30-DATEDIFF(now(),myads.updateDate)) as counter, othertable.somefield FROM myads JOIN othertable ON myads.id=othertable.myads_id";
(#10850)