# Get/ Create Table

**URL:** <https://forum.codewithmosh.com/t/get-create-table/13794>\
**Category:** SQL\
**Created:** [July 19, 2022, 12:59pm UTC](https://forum.codewithmosh.com/t/get-create-table/13794 "2022-07-19T12:59:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DarthVader](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@DarthVader](https://forum.codewithmosh.com/u/DarthVader)\
**Post date:** [July 19, 2022, 12:59pm UTC](https://forum.codewithmosh.com/t/get-create-table/13794/1 "2022-07-19T12:59:58Z")

</div>

The problem statement: I have a table with some values (Value a, value b) If value ‘a’ exists, i need to get the information from the row (ie. show values a, and b) If value ‘a’ does not exist, i need to create a row to insert value ‘a’ and value ‘b’  
How do i do this? I tried a few iterations, I am unable to do it properly. Please help

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [July 19, 2022, 2:28pm UTC](https://forum.codewithmosh.com/t/get-create-table/13794/2 "2022-07-19T14:28:35Z")

</div>

Hello.  
Welcome to the community.

I do not understand where do you take your data from?  
Say `a` do not exist. What value should `a` take?

---

<div class="post-metadata">

**Author:** ![DarthVader](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@DarthVader](https://forum.codewithmosh.com/u/DarthVader)\
**Post date:** [July 19, 2022, 2:43pm UTC](https://forum.codewithmosh.com/t/get-create-table/13794/3 "2022-07-19T14:43:24Z")

</div>

I have modified the problem. There is a table with a single column. I am writing a stored procedure to obtain a value from the user (Call the obtained value ‘a’). I Have to check if the entered value ‘a’ exists in the table. If it does, i have to return the value from the table. If it does not exist, i have to update the table with the value entered by the user (which is ‘a’).

Basically, if ‘a’ exists in the table, return the value. If it doesnt exist, update the table.  
(I am thinking i can add other columns in the table later as I am only checking for the values in this particular column)
