-1

I have this problem, which it's keeping me out of focus from the main project on Laravel.

I have 2 tables without any fk on them

TableA:
id(INT)
Name(VARCHAR)
EventId(INT)
PlayerChoiceId(INT)

and

TableB:
id(INT)
PlayerChoice(VARCHAR)
PlayerColor(VARCHAR)

I need to make a method on my controller to select all of the data from TableA with the PlayerChoice value, not the id from TableB, but without LEFT JOIN.

Example: id(TableA)|Name|EventId|PlayerChoice

miken32
  • 42,008
  • 16
  • 111
  • 154

1 Answers1

0

Something like:

SELECT a.*, b.PlayerChoice from TableA a, TableB b where a.PlayerChoiceId = b.id;

Will give you:

a.id a.Name a.EventId a.PlayerChoiceId b.PlayerChoice

is that what you're looking for?

Danial
  • 1,496
  • 14
  • 15
  • Something like that, in fact, I was more interested in the JSON output to return with the value in the PlayerChoice(TableB) column for the PlayerChoiceId(TableA) column. Something like this:[ { "id": 1,"name": "Name","EventId": 1, "PlayerChoice": "yes"}], instead of: [ { "id": 1,"name": "Name","EventId": 1, "PlayerOption":"1","PlayerChoice": "yes"}] I've had already implemented in older version of the app a table in HTML using a single SQL table and the structure was like this: id|Name(VARCHAR)|EventName(VARCHAR)|PlayerChoice(VARCHAR). – Bogdan Marian Muntean Nov 18 '20 at 01:46
  • Now,after some migrations, i altered the table, and the PlayerOption(PlayerChoiceId in the example) only changed from varchar to int, and the name of the column remains unchanged, the data from this column was moved to the new table(TableB), to store the id from the TableB. But i think it's ok, i'm going to modify the HTML table. – Bogdan Marian Muntean Nov 18 '20 at 01:46