rastaman46 Posted October 16, 2012 Share Posted October 16, 2012 Hey again well im trying to call 2 tables from sql "t1" content name "t2" got all records im matching them up by ID but result im get its row me in single rows Same name comes up few times diferent info same name but i need if name is same and have few recods im like to display like this "Name"-->first-->second-->and so on not like "Name" --> first "Name" --> second "Name" -->and so on did im was clear??? Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/ Share on other sites More sharing options...
ManiacDan Posted October 16, 2012 Share Posted October 16, 2012 but result im get its row me in single rows Same name comes up few times diferent info same nameYou're going to have to rewrite this in English, this makes no sense at all. Taking a complete shot in the dark: SELECT DISTINCT Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385620 Share on other sites More sharing options...
Barand Posted October 16, 2012 Share Posted October 16, 2012 That is way JOINS work - for each matching record you get the data from t1 joined with matching data from t2. To get what I think you want you will need to use GROUP BY coupled with GROUP_CONCAT() SELECT t1.id, GROUP_CONCAT(t2.name SEPARATOR ', ') as names FROM t1 INNER JOIN t2 ON t1.id = t2.id GROUP BY t1.id Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385639 Share on other sites More sharing options...
rastaman46 Posted October 17, 2012 Author Share Posted October 17, 2012 Hey and thanks for replay its most look my target but only get one result? Im got more then one name in it Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385811 Share on other sites More sharing options...
ManiacDan Posted October 17, 2012 Share Posted October 17, 2012 Im got no idea what you're talking about. Show what your tables look like, give us 6 rows of example data from each table. Show what your desired result looks like. Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385816 Share on other sites More sharing options...
rastaman46 Posted October 17, 2012 Author Share Posted October 17, 2012 First table Table 2 here what im trying to do Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385826 Share on other sites More sharing options...
Barand Posted October 17, 2012 Share Posted October 17, 2012 Still guessing. If this is wrong you'll have to explain better or run with it yourself. SELECT t1.betid, t1.bet_name, GROUP_CONCAT(t2.chosen_team SEPARATOR ', ') as teams FROM t1 INNER JOIN t2 ON t1.betid = t2.betid GROUP BY t1.betid Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385836 Share on other sites More sharing options...
rastaman46 Posted October 17, 2012 Author Share Posted October 17, 2012 Thanks works but haw do im add extra info in here GROUP_CONCAT(t2.chosen_team SEPARATOR ', ') im still want to display member id and bett size next to name ??? Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385841 Share on other sites More sharing options...
ManiacDan Posted October 17, 2012 Share Posted October 17, 2012 "I NEED GET LIKE THIS" Translation: Similar to this, but with extra information which fundamentally changes the nature of the query Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385842 Share on other sites More sharing options...
Barand Posted October 17, 2012 Share Posted October 17, 2012 GROUP_CONCAT(CONCAT(t2.member_id, '-', t2.chosen_team) SEPARATOR ', ') http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html#function_group-concat Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385854 Share on other sites More sharing options...
rastaman46 Posted October 18, 2012 Author Share Posted October 18, 2012 Thanks for your time im ill take over here Thanks for your time Link to comment https://forums.phpfreaks.com/topic/269543-sql-help-or-advice-need/#findComment-1385920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.