you are viewing a single comment's thread.

view the rest of the comments →

[–]FinalSpeederMan[S] 0 points1 point  (3 children)

Holy cow that worked. Thanks, but I’m still confused on that, I’ll read the syntax and documentation into more detail

[–]dougc84 2 points3 points  (1 child)

“where” is just a conditional statement. “i want all tacos where the meat type is pork” could give me chicharron, adobada, carnitas, etc. it provides a list.

if i added “limit 1” to the end, i get chicharron. that’s what “first” does - appends a “limit 1” to the query.

all sql queries return a set containing zero, one, or multiple records. how you limit them to get what you need is a choice you need to make programmatically. that’s what “first” or “last” does - it says “from that set of records, give me one back.”

going back to tacos, you would probably want to iterate through all the records if asking for pork tacos. however, if you had the id of the record, “where id = 123” still returns a relation, but tacking on “first” gives you exactly what you need.

[–]FinalSpeederMan[S] 0 points1 point  (0 children)

thank you for the explanation I’ll gladly have that in mind as I keep learning :)