ctcp Posted October 2, 2011 Share Posted October 2, 2011 table1 | credits | 100 | table2 | links | google.com | select table1 credits > 0 from table2 links ? i whant show from table2 links if table1 got credits Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/ Share on other sites More sharing options...
ctcp Posted October 2, 2011 Author Share Posted October 2, 2011 "SELECT * FROM table1, table2 WHERE table2.links > 0"; Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275019 Share on other sites More sharing options...
awjudd Posted October 2, 2011 Share Posted October 2, 2011 You are going to need to define what you want to do more. You could be doing this limitation in the PHP side of your application. If you really want to do it in SQL you could probably do something like this: SELECT * FROM table2 WHERE ( SELECT credits FROM table1 ) > 0 ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275020 Share on other sites More sharing options...
ctcp Posted October 3, 2011 Author Share Posted October 3, 2011 SELECT * FROM table2 WHERE ( SELECT credits FROM table1 ) > 0 ~juddster i got this error now Subquery returns more than 1 row php Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275251 Share on other sites More sharing options...
fenway Posted October 3, 2011 Share Posted October 3, 2011 I think you mean SUM(credits) -- and obviously, with some sort of link between the 2 tables. Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275257 Share on other sites More sharing options...
ctcp Posted October 3, 2011 Author Share Posted October 3, 2011 I think you mean SUM(credits) -- and obviously, with some sort of link between the 2 tables. i whant show record if the user got credits if not do not show Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275259 Share on other sites More sharing options...
fenway Posted October 3, 2011 Share Posted October 3, 2011 "Showing" has nothing to do with mysql -- you need the correct query to get the desired value first. Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275261 Share on other sites More sharing options...
ctcp Posted October 3, 2011 Author Share Posted October 3, 2011 "Showing" has nothing to do with mysql -- you need the correct query to get the desired value first. huh? can you get me the correct query? Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275262 Share on other sites More sharing options...
awjudd Posted October 3, 2011 Share Posted October 3, 2011 If you add the SUM that fenway suggested then it'll return one row again and work however it is not user specific. ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275263 Share on other sites More sharing options...
ctcp Posted October 3, 2011 Author Share Posted October 3, 2011 table1 User | credits | user1 | 100 | user2 | 0 | table2 user | links | user1 | google.com | user 2| xxx.com | how to query show link if user got credits Im sorry for first post i don't explane right Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275267 Share on other sites More sharing options...
awjudd Posted October 3, 2011 Share Posted October 3, 2011 SELECT User, credits, links FROM table1 t1 JOIN table2 t2 ON t1.User = t2.user WHERE t1.credits > 0 ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275269 Share on other sites More sharing options...
ctcp Posted October 3, 2011 Author Share Posted October 3, 2011 SELECT User, credits, links FROM table1 t1 JOIN table2 t2 ON t1.User = t2.user WHERE t1.credits > 0 ~juddster Column 'credits' in field list is ambiguous Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275273 Share on other sites More sharing options...
awjudd Posted October 3, 2011 Share Posted October 3, 2011 SELECT User, credits, links FROM table1 t1 JOIN table2 t2 ON t1.User = t2.user WHERE t1.credits > 0 ~juddster Column 'credits' in field list is ambiguous Not according to the table definition you provided us. Please do not skip small details when providing us information because it just makes the responses you get back not as useful as they can be. SELECT t1.User, t1.credits, t2.links FROM table1 t1 JOIN table2 t2 ON t1.User = t2.user WHERE t1.credits > 0 Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275275 Share on other sites More sharing options...
ctcp Posted October 3, 2011 Author Share Posted October 3, 2011 Many thanks My friend Solved Quote Link to comment https://forums.phpfreaks.com/topic/248291-how-to-select-multi-tables/#findComment-1275276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.