Jump to content

Sql Help Or Advice Need


rastaman46

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.